AWS CLI Commands for Managing CloudFormation Stacks

Created on: January 1, 2026 at UTC

AWS

This article is a collection of AWS CLI commands used while updating the CloudFormation stacks that support this blog.

Each command is grouped by its purpose, focusing on practical workflows for managing CloudFormation stacks safely and explicitly.

Assume an IAM Role Temporarily

Use the following command to assume an IAM role temporarily and output the credentials as a JSON file.

aws sts assume-role \
  --role-arn arn:aws:iam::000000000000:role/MyRole \
  --role-session-name my-session-name \
  --profile my-profile \
  > /tmp/creds.json

Set environment variables based on the generated JSON credentials file.

export AWS_ACCESS_KEY_ID=$(jq -r '.Credentials.AccessKeyId' /tmp/creds.json)
export AWS_SECRET_ACCESS_KEY=$(jq -r '.Credentials.SecretAccessKey' /tmp/creds.json)
export AWS_SESSION_TOKEN=$(jq -r '.Credentials.SessionToken' /tmp/creds.json)

Create a New CloudFormation Stack

Use this command to create a new CloudFormation stack.

aws cloudformation create-stack \
  --stack-name my-stack-name \
  --template-body file://my-template.yaml \
  --capabilities CAPABILITY_NAMED_IAM \
  --region ap-northeast-1

Update an Existing Stack with Parameters

Use this command to update an existing stack while passing parameters.

aws cloudformation update-stack \
  --stack-name my-stack-name \
  --template-body file://my-template.yaml \
  --capabilities CAPABILITY_NAMED_IAM \
  --region ap-northeast-1 \
  --parameters ParameterKey=KeyName,ParameterValue="Value"

Manually Start a Stack Rollback

Use this command to manually continue a stack rollback.

aws cloudformation continue-update-rollback \
  --stack-name my-stack-name \
  --region ap-northeast-1

Wait for Stack Rollback Completion

Use this command to wait until the rollback process is complete.

aws cloudformation wait stack-rollback-complete \
  --stack-name my-stack-name \
  --region ap-northeast-1

Create a Change Set to Import Existing Resources

Use this command to create a change set for importing existing (non-IaC) resources into a CloudFormation stack.

aws cloudformation create-change-set \
  --stack-name my-stack-name \
  --change-set-name my-change-set-name \
  --change-set-type IMPORT \
  --template-body file://my-template.yaml  \
  --resources-to-import file://my-import-definition.json \
  --region ap-northeast-1

Check the Status of a Change Set

Use this command to inspect the status and details of a change set.

aws cloudformation describe-change-set \
  --stack-name my-stack-name \
  --change-set-name my-change-set-name \
  --region ap-northeast-1

Execute a Change Set

Use this command to execute the prepared change set.

aws cloudformation execute-change-set \
  --stack-name my-stack-name \
  --change-set-name my-change-set-name \
  --region ap-northeast-1