1

I'm trying to grab the IP of users.

I followed guides on how to do this, and found answers that use event.source_ip in the lambda function, which connects to the API Gateway.

The result returns 'null' in my Lex & Facebook bots, and returns 'test-invoke-source-ip' in the API Gateway Test.

Lambda:

exports.handler = (event, context, callback) => {

    callback(null, event.source_ip);
};

API Gateway: Integration Request

enter image description here

1 Answer 1

1

Use lambda proxy integration, then you can handle the event and context from the lamda function yourself. You can read more here. https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html

You will need to return expected output for it to work.

Example using node (untested):

exports.handler = (event, context, callback) => {
 var res = {
   "statusCode": 200,
   "body": context.identity.sourceIp,
   "isBase64Encoded": false,
 }
 callback(null, res);
}
Sign up to request clarification or add additional context in comments.

1 Comment

To view the contents of event or context just use console.log them to view in cloudwatch logs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.