11

I want to be able to change my end point defined in each API Gateway method so that a staging environment called "Dev" points to my internal Dev API and Prod stage of course would route to my Production API.

Right now I'd have to manually change each method and then deploy to the prod stag but now to do any testing I'd have to change them all back again for a dev stage.

I am moving ahead with a DNS switch to move Dev to Prod but future development still requires a change on every method.

example:

I have a resource called User and a GET Method which maps to an end point (HTTP Proxy) -> http://dev.mytestapp.com/api/v1/user

I then deploy to a Stage called Dev - the Dev stage gives me a URL to call to request this resource, eg. https://xxxxobl.execute-api.us-east-1.amazonaws.com/dev/user

Now I test and it works as expected so I want to move this to a production stage, just called stage. When I deploy to prod, my calling url is now https://xxxxobl.execute-api.us-east-1.amazonaws.com/prod/user

but the problem is that the API is still mapping the end point to http://dev.mytestapp.com/api/v1/user and not something like http://prod.mytestapp.com/api/v1/user

So my stage and url have changed but the actual API being called is hard coded to dev.

Any ideas? Thanks

2
  • You should clarify your question. I'm not sure if you're using API Gateway correctly.
    – adamkonrad
    Commented Aug 6, 2015 at 19:45
  • Added an example - maybe I'm missing what a stage is really used for. Commented Aug 6, 2015 at 23:43

2 Answers 2

12

You can take advantage of stage variables to have end points route to different APIs. This page shows you how to set up a stage variable for a http proxy. You can use the stage variables for lambda functions as well.

4
  • 2
    Api Gateway team here, you're exactly right. Stage variables were built with dynamic endpoint mapping via stages in mind.
    – jackko
    Commented Dec 18, 2015 at 19:38
  • 2
    My Production env has https endpoint while dev has http. AWS doesn't let me set protocol as a variable. :(
    – Shipra
    Commented Sep 21, 2016 at 12:01
  • I'm confused whats the point of having prod and dev stages if both call the same lambda functions?
    – Diego
    Commented May 26, 2018 at 23:48
  • @Shipra Did you ever figure out a solution for this? I am also dealing with the same issue.
    – scorgn
    Commented Jun 6, 2019 at 18:27
0

having different stages mean having different environment for same lambda using same api.But different stages like pro,qa, test.

Not the answer you're looking for? Browse other questions tagged or ask your own question.