Getting an undefined variable message when calling Lambda function from Connect

0

I'm calling the code block below from Connect. I receive an error variable is undefined. Within connect when I test using the JSON { "key1": "654321" } The code works properly

From Connect the calling block is set up Function = alias of the Lambda function Function input parameters: Use attribute Destination key: key1 type: system Attribute: Customer ID

To me, it appears that the Parameters being passed in the Connect JSON string are correct.

Any help as to why the data is not being parsed properly when sent through Connect would be greatly appreciated

Logs show valid data being passed to the function { "Results": "The Lambda Function Returned An Error.", "ContactId": "e56bdf6c-923d-49d8-", "ContactFlowId": "arn:aws:connect:us-west-2:507182563096:instance/0cb6a294-6586-4aa3-b7cc-2b0f1516e0df/contact-fl", "ContactFlowName": "Connect-VoiceID-CareGiver-Contact-Flow_15", "ContactFlowModuleType": "InvokeExternalResource", "Timestamp": "2022-04-03T21:19:58.785Z", "ExternalResults": { "value": "707777", "attribute": "cid" }, "Parameters": { "FunctionArn": "arn:aws:lambda:us-west-2:507182563096:function:RHCS-VID-SMS", "Parameters": { "key1": "707777" }, "TimeLimit": "3000" } } Connect log shows:

Lambda log shows : INFO UI = undefined

const AWS = require('aws-sdk'); exports.handler = async (event) => {

console.log("UI = " + event.key1);

AWS.config.update({region: 'us-west-2'});
var params = {
    Message:  'DHCS-CG01|' + event.key1, 
    PhoneNumber: '+19999999999'
};

// Create promise and SNS service object
var publishTextPromise = new AWS.SNS({apiVersion: '2010-03-31'}).publish(params).promise();

return new Promise((resolve, reject) => {
    // Handle promise's fulfilled/rejected states
    publishTextPromise.then((data) => {
        console.log("MessageID is " + data.MessageId);
        const response = {
            statusCode: 200,
            headers: {
                "Content-Type": "application/json"
            },
            body: JSON.stringify(data)
        };
        console.log('Server response function');
        resolve(response);
    }).catch((error) => { reject(Error(error)); });
});
4개 답변
0

You should provide Lambda's logs because the error is from Lambda.

답변함 2년 전
0

I had included a snippet of the Lambda log here is a complete event as requested

START RequestId: 9e70f9f2-9887-40c1-9e97-af737f403946 Version: $LATEST

2022-04-03T21:19:59.330Z 9e70f9f2-9887-40c1-9e97-af737f403946 INFO UI = undefined

2022-04-03T21:20:00.024Z 9e70f9f2-9887-40c1-9e97-af737f403946 INFO MessageID is f66bb97a-3ed9-59bc-8488-e3be2f667a79

2022-04-03T21:20:00.062Z 9e70f9f2-9887-40c1-9e97-af737f403946 INFO Server response function

END RequestId: 9e70f9f2-9887-40c1-9e97-af737f403946

REPORT RequestId: 9e70f9f2-9887-40c1-9e97-af737f403946 Duration: 734.42 ms Billed Duration: 735 ms Memory Size: 128 MB Max Memory Used: 78 MB Init Duration: 417.37 ms

답변함 2년 전
0

When you're testing the Lambda are you using the right JSON string that mimics what Connects sends? I don't see where you get the right JSON parameter, I suspect that's the issue.

profile picture
dmacias
답변함 2년 전
0

The Connect log seems to show that it is sending: "FunctionArn": "arn:aws:lambda:us-west-2:507182563096:function:RHCS-VID-SMS", "Parameters": { "key1": "707777" }, "TimeLimit": "3000" } } Key1 would be correct and the target variable UI is defined console.log("UI = " + event.key1).

답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠