I've got an AWS API Gateway endpoint with a URL like this:
https://xxxxxxxxxx-vpce-09572222209cd2305.execute-api.us-west-1.amazonaws.com
I want to create an easy to remember alias for that name that I can use in my browser. I've already got an Nginx gateway that is redirecting to a number of other servers. So I just had to add a few lines to that machine's config: Here's what I'm doing right now:
location /myapi {
return 301 https://xxxxxxxxxx-vpce-09572222209cd2305.execute-api.us-west-1.amazonaws.com;
}
This works great. I can hit https://mydomain/myapi
with my browser and I get redirected to the real AWS endpoint URL.
But then I do a redeploy, and the URL changes. With this setup, I have to log onto my Nginx server and update the above entry in my config file to redirect to the new endpoint.
I'm wondering if there is any way to have Nginx obtain that URL from some dynamic location that my deployment code can update so that I don't have to manually edit the config file whenever the endpoint URL changes. Using DNS is my first thought. Is there any way to cause Nginx to do a CNAME lookup and then redirect to the result? Can you think of another way that I can get this dynamic behavior from Nginx?
I can't do a proxy to the endpoint because of SSL. My browser has to end up hitting the AWS URL so that the address in the request matches up with Amazon's certificate. I think a redirect is the only way to do this.
I believe that there is a way to do this within API Gateway, but it's complicated. I want to find something that's easier to do...something I can do pretty much on the fly without a lot of thought. I'll want to use this same technique over and over.