aws / aws/aws-sam-cli

Write to samconfig.toml sooner

Open
#3,693 3 comments 3 reactions 1 assignee Claimed by @qingchm View on GitHub
area/sam-config contributors/good-first-issue type/feature
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

### Describe your idea/feature/enhancement

Currently when using `sam deploy --guided` and the final steps fail for various reasons, the `samconfig.toml` file won't get written to.

This is _really_ annoying, especially for stacks with parameters.

Here's an example of me running `sam deploy --guided` with an expired SSO token. At the end of it I had no `samconfig.toml`-file and had to restart from the beginning.

```
$ sam deploy --guided

Configuring SAM deploy
======================

Looking for config file [samconfig.toml] : Not found

Setting default arguments for 'sam deploy'
=========================================
Stack Name [sam-app]: sam-typescript-test
AWS Region [eu-west-1]:
#Shows you resources changes to be deployed and require a 'Y' to initiate deploy
Confirm changes before deploy [y/N]:
#SAM needs permission to be able to create roles to connect to the resources in your template
Allow SAM CLI IAM role creation [Y/n]:
#Preserves the state of previously provisioned resources when an operation fails
Disable rollback [y/N]:
HelloWorldFunction may not have authorization defined, Is this okay? [y/N]: y
Save arguments to configuration file [Y/n]:
SAM configuration file [samconfig.toml]:
SAM configuration environment [default]:

Looking for resources needed for deployment:
Traceback (most recent call last):
File "botocore/credentials.py", line 2044, in _get_credentials
File "botocore/client.py", line 388, in _api_call
File "botocore/client.py", line 708, in _make_api_call
botocore.errorfactory.UnauthorizedException: An error occurred (UnauthorizedException) when calling the GetRoleCredentials operation: Session token not found or invalid

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "samcli/__main__.py", line 12, in
File "click/core.py", line 829, in __call__
File "click/core.py", line 782, in main
File "click/core.py", line 1259, in invoke
File "click/core.py", line 1066, in invoke
File "click/core.py", line 610, in invoke
File "samcli/lib/cli_validation/image_repository_validation.py", line 92, in wrapped
File "click/decorators.py", line 73, in new_func
File "click/core.py", line 610, in invoke
File "samcli/lib/telemetry/metric.py", line 166, in wrapped
File "samcli/lib/telemetry/metric.py", line 124, in wrapped
File "samcli/lib/utils/version_checker.py", line 41, in wrapped
File "samcli/cli/main.py", line 87, in wrapper
File "samcli/commands/_utils/cdk_support_decorators.py", line 38, in wrapped
File "samcli/commands/deploy/command.py", line 193, in cli
File "samcli/commands/deploy/command.py", line 255, in do_cli
File "samcli/commands/deploy/guided_context.py", line 559, in run
File "samcli/commands/deploy/guided_context.py", line 181, in guided_prompts
File "samcli/lib/bootstrap/bootstrap.py", line 23, in manage_stack
File "samcli/lib/utils/managed_cloudformation_stack.py", line 86, in manage_stack
File "samcli/lib/utils/managed_cloudformation_stack.py", line 97, in _create_or_get_stack
File "botocore/client.py", line 388, in _api_call
File "botocore/client.py", line 695, in _make_api_call
File "botocore/client.py", line 714, in _make_request
File "botocore/endpoint.py", line 102, in make_request
File "botocore/endpoint.py", line 132, in _send_request
File "botocore/endpoint.py", line 116, in create_request
File "botocore/hooks.py", line 357, in emit
File "botocore/hooks.py", line 228, in emit
File "botocore/hooks.py", line 211, in _emit
File "botocore/signers.py", line 93, in handler
File "botocore/signers.py", line 157, in sign
File "botocore/signers.py", line 237, in get_auth_instance
File "botocore/credentials.py", line 620, in get_frozen_credentials
File "botocore/credentials.py", line 515, in _refresh
File "botocore/credentials.py", line 531, in _protected_refresh
File "botocore/credentials.py", line 672, in fetch_credentials
File "botocore/credentials.py", line 682, in _get_cached_credentials
File "botocore/credentials.py", line 2046, in _get_credentials
botocore.exceptions.UnauthorizedSSOTokenError: The SSO session associated with this profile has expired or is otherwise invalid. To refresh this SSO session run aws sso login with the corresponding profile.
[159342] Failed to execute script __main__
```

### Proposal

Write to the file as values are entered

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.