chalice icon indicating copy to clipboard operation
chalice copied to clipboard

Feature request: Unique API Gateway names pr. stage

Open colde opened this issue 6 years ago • 13 comments

Since Chalice prefer to generate different API's instead of different stages when specifying a stage, it would be great if the API's actually had the environment prefixed. Otherwise it makes it really tricky in the console when mapping to a custom domain, or generally looking at things through the console.

https://github.com/aws/chalice/blob/master/chalice/deploy/deployer.py#L803 even has a mention of its usefulness, so i figured it might as well need an actual issue for tracking.

colde avatar Aug 22 '17 12:08 colde

Just capturing another thought. The name should probably be overridable by config, since some people prefer to deploy to individual stages in the same API, and they likely wont want to have that name be postfixed with the stage.

colde avatar Aug 22 '17 12:08 colde

@colde I am having a little bit of trouble trying to understand what the ask is. Could you give an example of when you deploy the chalice application of what you wound want the end url would be? For example, if I run chalice deploy the url is: https://yu7h0g07uh.execute-api.us-west-2.amazonaws.com/api/. Then if I deploy to a specific stage with chalice deploy --prod the url is: https://qgotoqrxu3.execute-api.us-west-2.amazonaws.com/api/.

kyleknap avatar Aug 23 '17 16:08 kyleknap

@kyleknap It is not really related the name of the endpoints themselves.

Really, I am talking about the "/Name" attribute on the API Gateway. (I.e. the one i change using a command like: aws apigateway update-rest-api --rest-api-id <ID> --patch-operations op=replace,path=/name,value=<NEW NAME>

The reason for this, is i like to have both a dev and a prod deployment, which is maintained using chalice stages. However, chalice then uses the exact same name for both API Gateway deployments.

When i then go to the API Gateway console, to map my deployments against the custom domain i have set up, i don't know which API is dev, and which is prod unless i compare the rest-api-id's.

If it is still not clear, i can try and take some screenshots. But really, I am just asking that the comment i linked to in the code, is actually something that gets done.

colde avatar Aug 24 '17 13:08 colde

Oh that makes sense now. It has nothing to do with the url, but just the name of the API Gateway API. Yeah I can see that as being useful as it is ambiguous as to which Chalice stage corresponds to which API Gateway API when looking at them in the console. Thanks for clarifying! Marking as a feature request.

kyleknap avatar Aug 24 '17 17:08 kyleknap

I haven't tried it, but I assume changing the api_gateway_stage config.json value wouldn't solve this problem. If it does, maybe it solves this issue? I'm in need of the same use case, a unique name for each chalice stage API in the AWS Console.

dmulter avatar Aug 16 '18 03:08 dmulter

+1. This can get very confusing when interacting with the console as you end up with multiple APIs all with the same name

MarkRuse avatar Aug 28 '18 06:08 MarkRuse

+1 As an example, I've deployed a few different chalice stages for the same project and this is what it ends up looking like in API gateway: image

wollerman avatar Dec 11 '18 17:12 wollerman

Hello,

I ended up to have different API name according to stages, but I exploited a trick on the chalice config file: elements in chalice stages declaration are consolidated from the parent elements. The below config works:

{
  "version": "2.0",
  "app_name": "myapp",
  "stages": {
    "dev": {
      "app_name": "myapp-dev",
      "environment_variables": {
        "ENV_NAME": "dev",
      }
    },
    "prod": {
      "app_name": "myapp-prod",
      "environment_variables": {
        "ENV_NAME": "prod",
      }
    }
  }
}

Specifying a different app_name in stage config will create an API with the declared name. You need to specify the app_name in top-level config too (without stage reference) because the lambda deployment will use it (lambda is already suffixed with env).

Then, to make it work, in app.py I need the environment variable to create the correct Chalice object according to the config:

import os
from chalice import Chalice

ENV_NAME = os.getenv('ENV_NAME')
app = Chalice(app_name='myapp-{}'.format(ENV_NAME))

"It work" but I feel it is not really "official". It may work because it is a side effect of the Chalice config and chalice internal mechanisms. I am not sure I will not have race conditions in the future.

npellegrin avatar Dec 19 '18 13:12 npellegrin

@npellegrin thanks for the "hack". i'll be using this until feature is implemented.

toringe avatar Jan 11 '19 12:01 toringe

I tried to change to description of the API gateway to make it less confusing, but that is removed on each deploy.

roelandmoors avatar Sep 19 '19 11:09 roelandmoors

@npellegrin any issues observed with this deployment style?

amarjandu avatar Nov 04 '19 22:11 amarjandu

Had the same idea in https://github.com/aws/chalice/issues/1286

Would be nice if we could fully customize the gateway name or at least add the stage as a suffix. (app_name + "-" + stage)

Pe-te avatar Nov 20 '19 09:11 Pe-te

This causes some confusion in Cloudwatch Alarms, each alarm works off the ApiName so if you have n number of API Gateways all with the same name it shows up as one. We've rolled out the solution from @npellegrin but it'd be nice to have a more official solution.

One issue I can see with the unofficial solution is the potential to deploy an entirely new api gateway if a developer changes the env variable, unlikely but not impossible.

mikebell avatar Mar 15 '22 08:03 mikebell