aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.51k stars 1.17k forks source link

sam deploy ignores --s3-bucket option #3753

Open paulthorburn opened 2 years ago

paulthorburn commented 2 years ago

Description:

I was thinking it would be nice to have 1 bucket for aws sam deployments rather than several randomly named buckets "aws-sam-cli-managed-default-samclisourcebucket-xxxxxxx". If. you try to do --guided with --s3-bucket switch is ignored and it will create a randomly named bucket for you.

Also the ' --resolve-s3 ' switch makes reference to a '--s3-guided' switch that does not exist.

Steps to reproduce:

sam deploy --guided --profile myadminprofile --s3-bucket SomeS3BucketNaneGoesHere

Observed result:

SAM creates a bucket "sam-cli-managed-default-samclisourcebucket-xxxxxxx"

Expected result:

SAM uses the bucket name i specify

Workaround:

sam deploy --guided .... sam delete edit samconfig.toml with new s3 bucket name sam deploy ...

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: OSX 12.2.1
  2. If using SAM CLI, sam --version: 1.40.1
  3. AWS region: us-west-2
prower-turnitin commented 2 years ago

I noticed this same issue along with the prefix and bucket options not working. I documented these issues at bottom of my Readme.md here https://github.com/prower-turnitin/sam-app-with-layers. Main point of that issue documentation is about issues with publishing to Serverless Application Repository. I mentioned issues I found with using .toml file and s3 flags at the bottom of that Readme.md.

qingchm commented 2 years ago

Hello there @paulthorburn @prower-turnitin I am sorry that this issue has been a pain point for you guys, but unfortunately is working as designed. For using --guided for --resolve-s3 options, we will by design use the default managed s3 location. Specifying an s3 location does not override that. I believe we have a option mechanism that errors out when both s3-bucket and resolve-s3 are provided, maybe we can have that kind of check on guided deployments as well. Let us know if you have any further questions!

ammarsaf commented 1 year ago

You can specify the bucket destination in samconfig.toml file under the following line

[default.deploy.parameters]
...
s3_bucket = "my-bucket"
s3_prefix = "my-object"

After the first sam deploy --guided, if you answered Yes to save configuration question, it will save the config it in samconfig.toml file. The next deployment, if you want to update your stack, just sam deploy without guided flag. And the above line and it will save within that bucket.