question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: sam delete keeps asking for --region found in samconfig.toml

See original GitHub issue

Description:

sam delete doesn’t let me delete a stack without providing a set of parameters already defined in the samconfig.toml file.

Steps to reproduce:

Create a stack with samconfig.toml looking a bit like this:

version = 0.1
[default]
[default.deploy]
[default.deploy.parameters]
s3_bucket = "<your bucket>"
s3_prefix = "<your prefix>"
kms_key_id = "<your S3 access key>"
region = "eu-central-1"
capabilities = "CAPABILITY_IAM"
image_repositories = []
confirm_changeset = false
disable_rollback = false

With this you should be able to deploy a stack based on template.yaml only by calling

sam build
sam deploy --stack-name mystack

Try deleting it:

sam delete --stack-name mystack --no-prompts --debug

Observed result:

sam delete --stack-name tsb-aim-production --no-prompts --debug
2022-08-14 15:55:23,217 | Using config file: samconfig.toml, config environment: default
2022-08-14 15:55:23,217 | Expand command line arguments to:
2022-08-14 15:55:23,217 | --stack_name=tsb-aim-production --no_prompts
2022-08-14 15:55:23,308 | Config file location: /c/user/git/tsb-lambda/samconfig.toml
2022-08-14 15:55:23,310 | Loading configuration values from [default.['deploy'].parameters] (env.command_name.section) in config file at '/c/user/git/tsb-lambda/samconfig.toml'...
2022-08-14 15:55:23,315 | Configuration values successfully loaded.
2022-08-14 15:55:23,315 | Configuration values are: {'s3_bucket': '[redacted]', 's3_prefix': 'tsb', 'kms_key_id': '[redacted]', 'region': 'eu-central-1', 'capabilities': 'CAPABILITY_IAM', 'image_repositories': [], 'confirm_changeset': False, 'disable_rollback': False}
Usage: sam delete [OPTIONS]

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

Expected result:

The SAM stack is deleted.

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

  1. OS: Windows 10 / WSL2 Ubuntu 20.04.4 LTS
  2. sam --version: SAM CLI, version 1.53.0
  3. AWS region: eu-central-1

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jfusscommented, Aug 15, 2022

@jsmucr You need to have default.delete.parameters in your samconfig.toml. They way the samconfig.toml operates is by command config. So deploy parameters will not be picked up in delete.

If you want to specify a region per environment (in your example default is the environment), you can add

[default.global.parameters]
region = "eu-central-1"

to the samconfig.toml, which should yield the results you want. https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html has more info on this.

0reactions
qingchmcommented, Dec 15, 2022

@cortexcompiler This mechanism is mainly aimed to focus on protecting users from accidentally deleting stacks if the stack name specified in command line option doesn’t match with what’s in the samconfig file, and you are poking at a direction where if the stack name is empty in the samconfig, it shouldn’t be treated the same way as having a different stack name and user should be able to proceed delete with other specified parameters like region?

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS SAM CLI configuration file
The AWS SAM CLI supports a project-level configuration file that stores default parameters for its commands. This configuration file is in the TOML...
Read more >
AWS Sam Hello World Failed - Stack Overflow
sam deploy --guided Looking for config file [samconfig.toml] : Not ... Name [sam-app]: AWS Region [eu-west-2]: #Shows you resources changes ...
Read more >
AWS SAM Deploy Missing option '--image-repository'...
I am trying to deploy to Lambda using `aws-sam-deploy` pipe and got an "Missing option '--image-repository' or '--image-repositories'" error when packaging.
Read more >
aws-sam-cli Changelog - pyup.io
fix: add `MaxAttempts` to `sam delete` by sriram-mv in ... users can turn cached builds off specifically even it is enabled in the...
Read more >
How to create serverless applications with SAM - Playing AWS
SAM (Serverless Application Model) is an open-source framework that ... if a samconfig.toml file exists and if not the AWS SAM CLI will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found