0 votes
1 view
in AWS by (18.2k 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 (42.5k 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);

};

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...