Compare commits

...

2 commits

2 changed files with 108 additions and 1 deletions

102
src/blog/post-4.md Normal file
View file

@ -0,0 +1,102 @@
---
title: 'AWS CLI Commands for Managing CloudFormation Stacks'
pubDate: 2026-01-01
author: 'Nakahara Daisuke'
tags: ["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.
```bash
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.
```bash
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.
```bash
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.
```bash
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.
```bash
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.
```bash
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.
```bash
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.
```bash
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.
```bash
aws cloudformation execute-change-set \
--stack-name my-stack-name \
--change-set-name my-change-set-name \
--region ap-northeast-1
```

View file

@ -88,4 +88,9 @@ h1 {
display: none; display: none;
} }
} }
pre,
code {
font-family: "JetBrains Mono", "Fira Code", "Menlo", "Consolas", monospace;
}