aws / aws/aws-cli

aws cloudformation deploy --output json does not output json

Open
#8,254 2 comments 10 reactions 0 assignees View on GitHub
cloudformation feature-request p3
Dominant language
Python
Stars
17.3k
Forks
4.6k
Avg merge
1d 2h
Merged PRs (30d)
13

Description

### Describe the bug

When using --output json or AWS_DEFAULT_OUTPUT=json with `aws cloudformation deploy` command, human-readable text is still produced as output.

```
AWS_DEFAULT_OUTPUT=json aws cloudformation --output json deploy --template-file ~/stack.yaml --stack-name stack-name --no-execute-changeset
```

Outputs:
```
Waiting for changeset to be created..
Changeset created successfully. Run the following command to review changes:
aws cloudformation describe-change-set --change-set-name arn:aws:cloudformation:us-east-1::changeSet/awscli-cloudformation-package-deploy-1697723449/c9695a27-8b16-4bc6-aa7f-866b3a333c39
```

### Expected Behavior

Some kind of stable json object would be produced, returning the change-set-name, e.g.

```
{
"CloudformationChangeSets": [
{"ChangeSetName": "arn:aws:cloudformation:us-east-1::changeSet/awscli-cloudformation-package-deploy-1697723440/c9695a27-8b16-4bc6-aa7f-866b3a333c34"
]
}
```

### Current Behavior

```
Waiting for changeset to be created..
Changeset created successfully. Run the following command to review changes:
aws cloudformation describe-change-set --change-set-name arn:aws:cloudformation:us-east-1::changeSet/awscli-cloudformation-package-deploy-1697723449/c9695a27-8b16-4bc6-aa7f-866b3a333c39
```

### Reproduction Steps

```
aws cloudformation --output json deploy --template-file ~/stack.yaml --stack-name stack-name
```

### Possible Solution

Return json and only json if requested by the user using --output json

### Additional Information/Context

It's important to provide json output for programmatic use. Perhaps `cloudformation deploy` is not intended for programmatic use, but it's difficult to achieve the same result as cloudformation deploy with other cli commands if you want to programmatically execute cloudformation with the option to preview and approve the changeset in the process, while executing everything in a nonidempotent way.

This is because `create-change-set` command only creates a changeset it an existing stack exists, and `create-stack` and `update-stack` require knowledge of whether the stack already exists.

Previewing a changeset in automation for a stack of unknown status thus requires

* run list-stack or describe-stack to determine if stack already exists
* create an empty stack if a stack does not already exist
* create the changeset against the stack
* preview the changeset
* (user interaction to approve the changset)
* apply the changeset if approved
* delete the stack if empty to clean up if the changeset was not approved

whereas, running the same procedure with cloudformation deploy:
* run `cloudformation deploy` with --no-execute-changeset
* (user interaction to approve the changeset)
* apply the changeset if approved

### CLI version used

aws-cli/2.13.27 Python/3.11.6

### Environment details (OS name and version, etc.)

ubuntu linux 22.04 and ubuntu linux 23.04

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.