chalice icon indicating copy to clipboard operation
chalice copied to clipboard

Chalice API Gateway endpoint vs local - paths are different

Open w- opened this issue 5 years ago • 2 comments

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

w- avatar Jun 10 '20 15:06 w-

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?

jamesls avatar Jun 22 '20 17:06 jamesls

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.

ima747 avatar Jul 07 '22 18:07 ima747

@jamesls any news about this --add-stage-prefix option?

mikgold avatar Oct 28 '22 14:10 mikgold