9

I have a scenario where I am using an API URL to invoke lambda function. After invoking the lambda function, I want that particular URL in the lambda function.

https://******.execute-api.eu-west-1.amazonaws.com/test/first

https://******.execute-api.eu-west-1.amazonaws.com/test/second

From this URL, I want the resource named first or second in lambda. Here the test is the stage name where I deplou\y my API. I have multiple resources created from that I want to change the behavior of lambda. How could I do this? Any help would be appreciated.

1 Answer 1

20

You can reconstruct the full url from values in the Lambda function's events variable.

events['headers']['Host'] = '******.execute-api.eu-west-1.amazonaws.com'
events['requestContext']['stage'] = 'test'
events['path'] = '/first'

So altogether, you can get https://******.execute-api.eu-west-1.amazonaws.com/test/first from adding them together:

'https://' + events['headers']['Host'] + '/' + events['requestContext']['stage'] + events['path']

See the Lambda Proxy integration part of the AWS documentation for details on other info you get can out of the events variable.

Sign up to request clarification or add additional context in comments.

Comments

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.