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.
First off all - sorry for not really answering your question correctly. Is there any way of running a bash-script or something similar during the deploy? I was thinking you could run a check-hostname function on the aws-side that cen be used, put together a correct URL and change it in the nginx-config. Run nginx -s reload to hotswap the config and everything should be up to date. (might be good to run a nginx -t to check if the configuration is sane, but if I'm not misstaking nxinx -s reload stops if the configuration has clear errors.)