rdegges rdegges - 6 months ago 42
Node.js Question

How can I retrieve a user's public IP address via Amazon API Gateway + Lambda (node)

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?

Answer

In the API Gateway, it's the value

$context.identity.sourceIp

http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#context-variable-reference

You can pass that through to your Lambda via a mapping template.

Comments