Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I'm currently writing a Node.js Lambda function, in which I want to log the incoming requester's public IP address. I've been looking through both the API Gateway and Lambda docs all day, but haven't found a solution.

Does the lambda event object include request metadata I can use to extract the user's IP?

1 Answer

0 votes
by (44.4k points)

API Gateway’s $context.identity.sourceIp demonstration in a Lambda function:

API Mapping template:

{

    "sourceIP" : "$context.identity.sourceIp"

}

Lambda function:

'use strict';

console.log('Loading function');

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

    console.log('SourceIP =', event.sourceIP);

    callback(null, event.sourceIP);

};

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

Browse Categories

...