sam deploy doesn't return the deployment result in exit code
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 1.2k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 52
Description
The deploy command of the CLI does not properly return the status of the deployment, but rather seems to return whether a rollback or delete action that followed the failed deployment was successful.
Command I'm running:
```
- sam deploy --stack-name ${STACK_NAME} \
--template-file packaged.yaml \
--capabilities CAPABILITY_NAMED_IAM \
--no-fail-on-empty-changeset \
--no-confirm-changeset \
--on-failure DELETE \
--s3-bucket ${O2C_CICD_BUCKET} \
--s3-prefix SAM/${CI_ENVIRONMENT_SLUG}
```
Output, showing arbitrary error in deployment...
```
2023-05-02 12:09:02 - Waiting for stack create/update to complete
CloudFormation events from stack operations (refresh every 5.0 seconds)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ResourceStatus ResourceType LogicalResourceId ResourceStatusReason
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE_IN_PROGRESS AWS::ApplicationInsights::Application ApplicationInsightsMonitoring -
CREATE_IN_PROGRESS AWS::ApplicationInsights::Application ApplicationInsightsMonitoring Resource creation Initiated
CREATE_FAILED AWS::ApplicationInsights::Application ApplicationInsightsMonitoring Resource handler returned message: "User:
arn:aws:sts::XXX:assumed-role/rol-
admin/myname@company.nl is not authorized to
perform:
applicationinsights:CreateApplication on
resource: arn:aws:applicationinsights:eu-
central-1:XXX:application/resource-
group/ApplicationInsights-SAM-sam-app because
no permissions boundary allows the
applicationinsights:CreateApplication action
(Service: ApplicationInsights, Status Code:
400, Request ID:
abcdefg-f548-4d77-ac9c-5dfe81053886)"
(RequestToken:
abcdefg-2734-d5fa-d2e6-ce693ed9fa43,
HandlerErrorCode: InternalFailure)
UPDATE_ROLLBACK_IN_PROGRESS AWS::CloudFormation::Stack sam-app The following resource(s) failed to create:
[ApplicationInsightsMonitoring].
UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS AWS::CloudFormation::Stack sam-app -
DELETE_IN_PROGRESS AWS::ApplicationInsights::Application ApplicationInsightsMonitoring -
DELETE_COMPLETE AWS::ApplicationInsights::Application ApplicationInsightsMonitoring -
UPDATE_ROLLBACK_COMPLETE AWS::CloudFormation::Stack sam-app -
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Stack sam-app has rolled back successfully
$ echo Last exit code is $?
Last exit code is 0
```
Expected an exit code that doesn't equal 0 as my stack did not deploy properly.
Now I have to keep track of the status of the stack myself using the AWS CLI somehow, which is still very error prone and hard to get right. In my CI/CD tool I want to use exit codes to stop the process and notify the user that something is wrong.
Perhaps an option to return an error when the deployment fails, like --fail-on-deployment-failure, which will make the CLI return an exit code that represents the stack depployment result.
Contributor guide
Research direction
Start by reproducing the reported `sam deploy` command with a deployment that fails and then rolls back, and inspect how the deploy command determines its final exit status. Done means a failed deployment returns a nonzero exit code even when rollback or deletion succeeds, while a successful deployment retains a zero exit code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- cli, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100