Chalice: Deploy stages to different regions

Created on 5 Mar 2020  路  7Comments  路  Source: aws/chalice

I'm wondering what is the best way to achieve this. I've seen a couple of closed issues around the same topic, but none seem to provide a clear and final answer.

The best I found suggests using different profiles and then setting an AWS_PROFILE env var in the stage, but then the lambda that gets deployed cannot find such profile and crashes.

What are people using to accomplish this that is not just changing the profile before running chalice --deploy or having to specify a --profile?

feature-request

Most helpful comment

Just to make sure I understand what you're asking for, you'd prefer to set your region in your .chalice/config.json file, per stage? So something like this:

{
  "version": "2.0",
  "app_name": "asdf2",
  "stages": {
    "dev": {
      "api_gateway_stage": "api",
      "region": "us-west-2"
    },
    "prod": {
      "region": "us-west-1"
    }
  }
}

Is that correct?

All 7 comments

The best I found suggests using different profiles and then setting an AWS_PROFILE env var in the stage, but then the lambda that gets deployed cannot find such profile and crashes.

This should work. If it can't find the profile I'd double check your ~/.aws/config file to ensure that the profile is defined.

What are people using to accomplish this that is not just changing the profile before running chalice --deploy or having to specify a --profile?

Chalice will pick up the region configuration from the same places the SDK does so if you don't want to set your region as part of your profile in your ~/.aws/config file, you can also set the AWS_DEFAULT_REGION env var to deploy to a different region.

Just to avoid confusion, when I talk about setting env vars per stage, i'm talking about config.json and defining the env var there. Doing it via an export is not ideal as I may close my terminal or similar and forget to export and then my lambda gets deployed to a different region. Or I may forget to switch it between dev and prod.

So what does crash is the lambda that is deployed, not in my local machine but in AWS, because the AWS_PROFILE env var gets set on the lambda and then the lambda is trying to find that profile on the execution environment which does not exist.

Same goes for AWS_DEFAULT_REGION. If i set that on the config.json, when i try to deploy i get An error occurred (InvalidParameterValueException) when calling the CreateFunction operation: Lambda was unable to configure your environment variables because the environment variables you have provided contains reserved keys that are currently not supported for modification. Reserved keys used in this request: AWS_DEFAULT_REGION

I think it would be really useful to be able to define the region/profile for each stage independently from the environment variables.

Just to make sure I understand what you're asking for, you'd prefer to set your region in your .chalice/config.json file, per stage? So something like this:

{
  "version": "2.0",
  "app_name": "asdf2",
  "stages": {
    "dev": {
      "api_gateway_stage": "api",
      "region": "us-west-2"
    },
    "prod": {
      "region": "us-west-1"
    }
  }
}

Is that correct?

Correct, something like that would be great. I guess it could be useful for many chalice users.

btw, more than happy to help working on that feature if it's something that the chalice community thinks would be good to have.

also, and sorry to scatter comments around, forgot to mention it on the previous message. Either a 'region' option or also a 'profile' option would be fine, but I guess 'region' is a bit broader, as profile names may be very specific to a developer environment. But still I guess the 'profile' option would also be useful for some.

Any update? Also looking for something similar. Would like to set the region from within app.py or config.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Miserlou picture Miserlou  路  4Comments

carlkibler picture carlkibler  路  4Comments

variable picture variable  路  4Comments

kortina picture kortina  路  3Comments

jarretraim picture jarretraim  路  3Comments