Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAM delete doesn't detect region. #5248

Closed
garretwilson opened this issue Jun 2, 2023 · 4 comments
Closed

SAM delete doesn't detect region. #5248

garretwilson opened this issue Jun 2, 2023 · 4 comments

Comments

@garretwilson
Copy link

I'm using SAM 1.84.0 on Windows 10.

I can deploy a stack using something like this:

sam deploy \
    --profile my-aws-profile \
    --template-file $SCRIPT_DIR/sam-template.yaml \
    --stack-name my-stack \
    --s3-bucket sam-bucket

Note that I don't specify a region anywhere. My samconfig.toml doesn't contain anything about a region. I have set up a default region in my-aws-profile, which is standard for AWS CLI work. For example my ~/.aws/cofig might look like this:

[default]
region = us-east-1
output = json

[profile my-aws-profile]
region = us-east-2
output = json

That all works as expected. But then it comes time to delete the stack:

sam delete \
    --profile my-aws-profile \
    --stack-name my-stack \
    --s3-bucket sam-bucket
    --no-prompts

Unfortunately that produces:

Error: Missing option '--region', region is required to run the non guided delete command.

But I don't want to remember what region to use and provide a --region on the command line. The region is already known because I specified a --profile, for while a region is specified. Again this is standard AWS CLI configuration.

I didn't need to specify a --region when I ran sam deploy …. I shouldn't be required to provide a --region when I delete the same stack, providing the same information, when running sam delete ….

This is not just an inconvenience: it is a duplication of information that promotes errors in the future. We have a centralized location for defining the profile, and it gets passed to the batch files as $awsProfile. Imagine for example that we take this project and simply change $awsProfile. The entire deployment will work exactly the same, except that it will use the other AWS profile in the appropriate region. But because sam delete … requires a separate --region designation (even though it should already know that information, just as sam deploy … does), what happens if we forget to go update the --region information in the batch files when we update $awsProfile? The whole thing breaks — needlessly.

Please update the sam delete … logic to determine the region based upon the AWS profile in the standard AWS CLI ~/.aws/cofig configuration, as it does for sam deploy ….

@garretwilson garretwilson added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Jun 2, 2023
@hoffa hoffa transferred this issue from aws/serverless-application-model Jun 2, 2023
@jfuss
Copy link
Contributor

jfuss commented Jun 2, 2023

@garretwilson Thanks for reporting. sam delete seems to behave/was implemented differently than our other commands. What you are doing should work but looks like we are doing custom things: https://github.com/aws/aws-sam-cli/blob/develop/samcli/commands/delete/delete_context.py#L111-L122 instead of using boto3 directly (like we do other places). Using boto3 allows for the right resolution to happen.

Marking this as a bug.

@jfuss jfuss added type/bug area/delete and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Jun 2, 2023
@jfuss
Copy link
Contributor

jfuss commented Jun 21, 2023

Patch is released in v1.87.0. Closing

@jfuss jfuss closed this as completed Jun 21, 2023
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@garretwilson
Copy link
Author

I just tested with v1.88.0, and it appears this fixed the problem. Thank you, @jfuss! Have a great weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants