By using AWS re:Post, you agree to the Terms of Use
/Getting an undefined variable message when calling Lambda function from Connect/

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 Answers
0

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

answered 3 months ago
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

answered 3 months ago
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.

answered 3 months ago
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).

answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions