aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

sam deploy command option for different config file

Open ericallam opened this issue 7 years ago • 24 comments

Describe your idea/feature/enhancement

I'd like to be able to have multiple different samconfig.toml files for deploying to different environments in my CI/CD process.

Proposal

Add an option flag to sam deploy that allows a user to specify a path to a samconfig.toml path, like so:

$ sam deploy --config-file ./samconfig-dev.toml

The guided mode should also be updated to ask for the path name, possible right after the Save arguments to samconfig.toml: input step.

ericallam avatar Nov 28 '19 11:11 ericallam

This is a good feature request. We had made the explicit decision to skip this to support more automatic resolution mechanisms of the config file.

What do you think about an automatic resolution mechanism where you specify the env sam deploy --env dev and SAM CLI automatically chooses samconfig-<env>.toml?

sanathkr avatar Dec 09 '19 18:12 sanathkr

@sanathkr That would work for my use case 👍

ericallam avatar Dec 10 '19 11:12 ericallam

I like to have multiple stacks in my application repo (e.g. splitting front-end and back-end resources), so I don't think the --env approach works.

Really I just want to be able to support a custom configuration file name, so that I can specify where to load settings from, just like I would when specifying different template files - it feels like there is always going to be a 1:1 mapping between template file and config file, so why not support specifying them the same way?

rowanu avatar Dec 29 '19 00:12 rowanu

I agree with @rowanu. I'd rather start with a simple generic mechanism, --config-file, that can enable all sorts of use cases. Then we can see what people use it for, and build an opinionated version (like --env) based on that.

benkehoe avatar Dec 31 '19 18:12 benkehoe

Additionally, with the ability to use a separate configuration file should come the ability for "guided" mode to not actually deploy but write the values to a new config file location.

benkehoe avatar Dec 31 '19 18:12 benkehoe

I need multiple configs for all of:

  1. the same stack copied to multiple accounts
  2. a slightly different stack in dev vs test vs prod
  3. a set of different stacks together in the same place comprising an application

I can accomplish all of them with --config-file.

benkehoe avatar Dec 31 '19 18:12 benkehoe

I would also be in favor of being able to define multiple profiles inside of a single samconfig.toml similar to AWS credentials file. There are already namespaces in there for [default], why not also support other profile names that you could choose to override the default.

Does this belong in a separate issue?

jdonboch avatar Jan 23 '20 21:01 jdonboch

It seems there is a hidden feature (or at least not yet documented) here with "--config-env" :

[default.validate.parameters]
template_file = "template-dev.yaml"

[prod.validate.parameters]
template_file = "template-prod.yaml"
$ sam validate
template-dev.yaml is a valid SAM Template

$ sam validate --config-env prod
template-prod.yaml is a valid SAM Template

:)

darylounet avatar Feb 03 '20 16:02 darylounet

@darylounet I would not rely on this at the moment. I think we initially had some design but pulled it out to start with the single config file. See https://github.com/awslabs/aws-sam-cli/issues/1615#issuecomment-563357713 above.

jfuss avatar Feb 03 '20 17:02 jfuss

@jfuss however I really think it's the good way to go. I have 5 environments, it's ridiculous to have 5 files, don't you think ?

darylounet avatar Feb 06 '20 12:02 darylounet

@jfuss I'm not against adding a config-file option, but I'm totally in favor of the undocumented feature @darylounet points out. I think there are use cases for both, but the current --config-env is more elegant.

I will, however, point out that the label of "environment" is semantic to the application itself. What we are really talking about are stack labels.

I recommend implementing --config-file as requested (and not enforce a naming convention), and possibly making the existing --config-env cannon, except maybe call it --stack. Having both of these features will give developers a lot of versatility in how they address the many configuration they can have across many accounts.

sbbowers avatar Feb 06 '20 18:02 sbbowers

@darylounet We haven't made a decision on what is best here. There are defiantly case for both solutions.

@sbbowers We are planning on removing, as this was never meant to be available: https://github.com/awslabs/aws-sam-cli/pull/1769 Originally, we thought about this but didn't have enough to understand if this was the right choice. It was meant to be hidden in the code to be able to expand later not hidden and still available from the command line. This is why it is not documented, because it was never meant to be there.

jfuss avatar Feb 06 '20 18:02 jfuss

It seems like the two cases are compatible. --config-file determines the file that configuration is loaded from. --config-env determines what elements to use from the config file that was loaded.

Separate quibble: it seems like because of the similarity with the AWS CLI config files, it should maybe be a "profile", not an "env". It doesn't have to be a separate environment, it could just be a different bucket to use within the same environment, or even literally just using a different credentials profile.

benkehoe avatar Feb 07 '20 14:02 benkehoe

I agree with @benkehoe. I would love to see this feature, and I think guided mode without an actual deployment would be helpful too.

Also, having a bit more docs explaining what are the allowed/expected params in this samconfig.toml file would be excellent.

stojanovic avatar Feb 14 '20 10:02 stojanovic

Has anyone come up with a workaround for this in the meantime? How do you manage pushing to dev / test environments? Having to use -g every time is annoying and fragile.

Edit: Oh, just found this:

If you are using SAM for a non-interactive deployment, it is possible to pass all required information as parameters. For example, for a continuous integration continuous delivery (CICD) pipeline:

from https://aws.amazon.com/blogs/compute/a-simpler-deployment-experience-with-aws-sam-cli/

I think I can work with that...

mariaines avatar Feb 26 '20 02:02 mariaines

It is surprising to remove a workaround possibility from your users before even proposing a solution ... For those who wish to keep the workaround while using the latest sam cli versions you can revert the patch :

cd "$(dirname "$(which sam)" )/../lib/python/site-packages"
wget https://github.com/awslabs/aws-sam-cli/commit/1b7b4c9b11b5149b333d1dd20458293d5d4af6d4.patch
patch -R samcli/cli/cli_config_file.py 1b7b4c9b11b5149b333d1dd20458293d5d4af6d4.patch
rm 1b7b4c9b11b5149b333d1dd20458293d5d4af6d4.patch

darylounet avatar Mar 03 '20 14:03 darylounet

This option with different config file would be definitely good to have!

revolutionisme avatar May 07 '20 11:05 revolutionisme

What is the issue with the --config-env ? personally I believe this behavior is perfect for this use case

ronaldour avatar Jun 07 '20 01:06 ronaldour

I'm going to throw my support behind @benkehoe for having a file path option and not just setting an env.

brysontyrrell avatar Jun 26 '20 17:06 brysontyrrell

@benkehoe We also would like to have this functionality. As we are working in a Landing Zone where we do have staging accounts (DEV, TEST, PROD) for each product, we would like to deploy a SAM application via CICD with a separate samconfig.toml for each account.

kirnberger1980 avatar Jul 03 '20 08:07 kirnberger1980