aws cli commands related to cloudformation:¶
deploy a new stack from cli:¶
aws cloudformation deploy --template-file ./ec2_instance_template.yml \
--stack-name dolcf0x002 --parameter-overrides "KeyName=dkoleary@2023" \
"InstanceType=t2.nano" "PublicLocation=24.15.136.94/32"
Redploy stack when in ROLLBACK_COMPLETE state:¶
Delete it first:
aws cloudformation delete-stack --stack-name dolcf0x002
aws cloudformation deploy --template-file ./ec2_instance_template.yml \
--stack-name dolcf0x002 --parameter-overrides "KeyName=dkoleary@2023" \
"InstanceType=t2.nano" "PublicLocation=24.15.136.94/32"
Update a deployed stack when template is changed:¶
aws cloudformation update-stack --template-body file://dbaccess.yaml \
--stack-name dolstack0x002
See outputs from stacks:¶
complete json dump: ……………….,
$ aws cloudformation describe-stacks --stack-name dolcf0x002
[[lots of json snipped]]
retrieving just the outputs:¶
$ aws cloudformation describe-stacks --stack-name dolcf0x002 --query "Stacks[0].Outputs"
[
{
"OutputKey": "InstanceId",
"OutputValue": "i-096b197430a6484f4",
"Description": "InstanceId of the EC2 instance"
},
{
"OutputKey": "PublicIP",
"OutputValue": "3.15.29.181",
"Description": "Public IP address of the EC2 instance"
},
{
"OutputKey": "AZ",
"OutputValue": "us-east-2a",
"Description": "AZ of the EC2 instance"
},
{
"OutputKey": "PublicDNS",
"OutputValue": "ec2-3-15-29-181.us-east-2.compute.amazonaws.com",
"Description": "Public DNSName of the EC2 instance"
}
]
to retrieve just one element:¶
aws cloudformation describe-stacks --stack-name dolcf0x002 \
--query "Stacks[0].Outputs[?OutputKey=='PublicIP'].OutputValue" \
--output text
3.15.29.181
To retrieve list of stacks:¶
Active stacks:¶
$ aws cloudformation list-stacks --output table \
--stack-status-filter "CREATE_COMPLETE" "CREATE_IN_PROGRESS" \
--query 'StackSummaries[*].[StackName,StackStatus]'
-----------------------------------
| ListStacks |
+-------------+-------------------+
| dolcf0x002 | CREATE_COMPLETE |
+-------------+-------------------+
All stacks:¶
$ aws cloudformation list-stacks --region us-east-1 --output table \
--query 'StackSummaries[*].[StackName,StackStatus,CreationTime,DeletionTime]'
-------------------------------------------------------------------------------------------
| ListStacks |
+------------+------------------+----------------------------+----------------------------+
| dolcf0x002| DELETE_COMPLETE | 2023-08-27T18:52:56.323Z | 2023-08-27T19:10:42.371Z |
| dolcf0x002| DELETE_COMPLETE | 2023-08-27T18:49:10.332Z | 2023-08-27T18:52:05.160Z |
| dolcf0x002| DELETE_COMPLETE | 2023-08-27T18:34:58.786Z | 2023-08-27T18:46:28.572Z |
+------------+------------------+----------------------------+----------------------------+