Reputation: 577
Im using the serverless framework to build a REST API which runs on AWS Lambda. The app has a custom authorizer which verifies the access token. Everything up to this point is working great.
New tokens are generated inside my app and can be restricted by IP, CIDR etc. Now I want my custom authorizer to be able to allow/deny requests based on this setting. I'm not able to get the source IP inside the authorizer but I'm able to get that on the lambda functions.
If the authorizer has no way to access the IP then is there a way to execute some common logic before each lambda is run?
Upvotes: 1
Views: 371
Reputation: 128
You Need to do following:
API Gateway’s $context.identity.sourceIp
demonstration in a Lambda function
API Mapping template:
{
"sourceIP" : "$context.identity.sourceIp"
}
Lambda Function:
print(event.sourceIP)
Upvotes: -1