bdifferent
bdifferent

Reputation: 703

AWS Gateway map path for lambda

I am working in AWS with the API gateway together with a lambda function. I read about how to pass parameters over to lambda function, that is fine. But I want to pass the whole path over to lambda. Does someone know how that would be done? Especially I want to pass the stage of the API gateway. The lambda function should connect to either the test server or the prod based on the stage. In the following example it would be test:

https://skjdfsdj.execute-api.us-east-1.amazonaws.com/test/name/name2

In next example it would be prod:

https://skjdfsdj.execute-api.us-east-1.amazonaws.com/prod/name/name2

Any information how that would work?

Thanks, Benni

Upvotes: 1

Views: 473

Answers (1)

nams
nams

Reputation: 81

We can configure/deploy the API Gateway with respect to the stages and the HTTP Methods that are required Docs. There may be two cases :

  • You may either have two different AWS lambda functions implemented, in this scenario its pretty simple as you can just create another stage and map the lambda function and the respective methods accordingly.Add another stage
  • If you have to access the same lambda function and take action corresponding to the stage, You can add, remove, and edit stage variables and their values. You can use stage variables in your API configuration to parametrize the integration of a request. Stage variables are also available in the $context object of the mapping templates, and once we have mapped the particular stage variable in the incoming request you can use it and configure which server to call accordingly. Do check this out API Gateway context/stage variables

Upvotes: 2

Related Questions