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.
You can find a REST API's root URL in the Stage Editor for the API in the API Gateway console. It's listed as the Invoke URL at the top. If the API's root resource exposes a GET method without requiring user authentication, you can call the method by clicking the Invoke URL link.
[Answer] There is nothing wrong with this model. And yes, you can call this API (Lambda proxy) as any Rest API.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With