chalice
chalice copied to clipboard
Chalice API Gateway endpoint vs local - paths are different
When deploying our chalice app, we will get an API Gateway url of the form
https://<aws url>/<api gateway stage>/
e.g.
https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/prod/
when testing locally using chalice local how do we simulate the <api gateway stage> in the path?
Finding it difficult to do some local sanity testing because the paths end up all different
There's not really a way to do this right now. The way I've usually handled this is to have a URL_PREFIX that for local testing is empty and for prod has the stage name in it. Then we creating URLs I just add the URL_PREFIX before whatever URL I'm constructing.
I think to address this, we could add a new --url-prefix parameter or even just a --add-stage-prefix to chalice local which would allow the URLs match up exactly. Would that be helpful for you?
The --add-stage-prefix approach would be perfect for my use case and a few others I think I may want in future. This would enable me to optionally match the URLs to my various environments and deployments, etc. entirely within the local environment, meaning that my front end doesn't need any knowledge of what the backend is doing. This simplifies the proxy configuration for local testing considerably and prevents any need to adapt the front end path targets in any way. The nice thing about --add-stage-prefix is I can just specify stage and an additional flag when starting chalice local and it keeps my config in one place, instead of needing to have a stage config and then specify --url-prefix with a matching value. I could argue that that flag should be on by default for consistency, but since there's an established expectation (and maybe you don't want the stage for local testing at all) that would break stuff.
@jamesls any news about this --add-stage-prefix option?