Skip to content

Commit c27e655

Browse files
authored
Merge pull request aws#9813 from elysahall/awsdocs-10-23-25
CLI examples for cloudformation.
2 parents 4eec84e + c26a861 commit c27e655

12 files changed

+409
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
**To create a generated template from scanned resources**
2+
3+
The following ``create-generated-template`` example creates a generated template named ``MyTemplate`` from scanned resources. ::
4+
5+
aws cloudformation create-generated-template \
6+
--generated-template-name MyTemplate \
7+
--resources file://resources.json
8+
9+
Contents of ``resources.json``::
10+
11+
[
12+
{
13+
"ResourceType": "AWS::EKS::Cluster",
14+
"LogicalResourceId":"MyCluster",
15+
"ResourceIdentifier": {
16+
"ClusterName": "MyAppClusterName"
17+
}
18+
},
19+
{
20+
"ResourceType": "AWS::AutoScaling::AutoScalingGroup",
21+
"LogicalResourceId":"MyASG",
22+
"ResourceIdentifier": {
23+
"AutoScalingGroupName": "MyAppASGName"
24+
}
25+
},
26+
{
27+
"ResourceType": "AWS::EKS::Nodegroup",
28+
"LogicalResourceId":"MyNodegroup",
29+
"ResourceIdentifier": {
30+
"NodegroupName": "MyAppNodegroupName"
31+
}
32+
},
33+
{
34+
"ResourceType": "AWS::IAM::Role",
35+
"LogicalResourceId":"MyRole",
36+
"ResourceIdentifier": {
37+
"RoleId": "arn:aws::iam::123456789012:role/MyAppIAMRole"
38+
}
39+
}
40+
]
41+
42+
Output::
43+
44+
{
45+
"Arn":
46+
"arn:aws:cloudformation:us-east-1:123456789012:generatedtemplate/7fc8512c-d8cb-4e02-b266-d39c48344e48",
47+
"Name": "MyTemplate"
48+
}
49+
50+
For more information, see `Create a CloudFormation template from resources scanned with IaC generator <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/iac-generator-create-template-from-scanned-resources.html>`__ in the *AWS CloudFormation User Guide*.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
**To create the stack definition for a stack refactor operation**
2+
3+
The following ``create-stack-refactor`` example creates the stack definition for stack refactoring. ::
4+
5+
aws cloudformation create-stack-refactor \
6+
--stack-definitions \
7+
StackName=Stack1,TemplateBody@=file://template1-updated.yaml \
8+
StackName=Stack2,TemplateBody@=file://template2-updated.yaml
9+
10+
Output::
11+
12+
{
13+
"StackRefactorId": "9c384f70-4e07-4ed7-a65d-fee5eb430841"
14+
}
15+
16+
For more information, see `Stack refactoring <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stack-refactoring.html>`__ in the *AWS CloudFormation User Guide*.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
**To delete a generated template**
2+
3+
The following ``delete-generated-template`` example deletes the specified template. ::
4+
5+
aws cloudformation delete-generated-template \
6+
--generated-template-name MyTemplate
7+
8+
This command produces no output.
9+
10+
For more information, see `Generating templates from existing resources <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/generate-IaC.html>`__ in the *AWS CloudFormation User Guide*.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
**To describe a generated template**
2+
3+
The following ``describe-generated-template`` example describes the specified template. ::
4+
5+
aws cloudformation describe-generated-template \
6+
--generated-template-name MyTemplate
7+
8+
Output::
9+
10+
{
11+
"GeneratedTemplateId": "arn:aws:cloudformation:us-east-1:123456789012:generatedTemplate/7d881acf-f307-4ded-910e-f8fb49b96894",
12+
"GeneratedTemplateName": "MyTemplate",
13+
"Resources": [
14+
{
15+
"ResourceType": "AWS::EC2::SecurityGroup",
16+
"LogicalResourceId": "EC2SecurityGroup",
17+
"ResourceIdentifier": {
18+
"Id": "sg-1234567890abcdef0"
19+
},
20+
"ResourceStatus": "COMPLETE",
21+
"ResourceStatusReason": "Resource Template complete",
22+
"Warnings": []
23+
},
24+
{
25+
"ResourceType": "AWS::EC2::Instance",
26+
"LogicalResourceId": "EC2Instance",
27+
"ResourceIdentifier": {
28+
"InstanceId": "i-1234567890abcdef0"
29+
},
30+
"ResourceStatus": "COMPLETE",
31+
"ResourceStatusReason": "Resource Template complete",
32+
"Warnings": []
33+
},
34+
{
35+
"ResourceType": "AWS::EC2::KeyPair",
36+
"LogicalResourceId": "EC2KeyPairSshkeypair",
37+
"ResourceIdentifier": {
38+
"KeyName": "sshkeypair"
39+
},
40+
"ResourceStatus": "COMPLETE",
41+
"ResourceStatusReason": "Resource Template complete",
42+
"Warnings": []
43+
}
44+
],
45+
"Status": "COMPLETE",
46+
"StatusReason": "All resources complete",
47+
"CreationTime": "2025-09-23T19:38:06.435000+00:00",
48+
"LastUpdatedTime": "2025-09-23T19:38:10.798000+00:00",
49+
"Progress": {
50+
"ResourcesSucceeded": 3,
51+
"ResourcesFailed": 0,
52+
"ResourcesProcessing": 0,
53+
"ResourcesPending": 0
54+
},
55+
"TemplateConfiguration": {
56+
"DeletionPolicy": "RETAIN",
57+
"UpdateReplacePolicy": "RETAIN"
58+
},
59+
"TotalWarnings": 0
60+
}
61+
62+
For more information, see `Generating templates from existing resources <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/generate-IaC.html>`__ in the *AWS CloudFormation User Guide*.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
**To describe a resource scan**
2+
3+
The following ``describe-resource-scan`` example describes the resource scan with the specified scan ID. ::
4+
5+
aws cloudformation describe-resource-scan --region \
6+
--resource-scan-id arn:aws:cloudformation:us-east-1:123456789012:resourceScan/0a699f15-489c-43ca-a3ef-3e6ecfa5da60
7+
8+
Output::
9+
10+
{
11+
"ResourceScanId": "arn:aws:cloudformation:us-east-1:123456789012:resourceScan/0a699f15-489c-43ca-a3ef-3e6ecfa5da60",
12+
"Status": "COMPLETE",
13+
"StartTime": "2025-08-21T03:10:38.485000+00:00",
14+
"EndTime": "2025-08-21T03:20:28.485000+00:00",
15+
"PercentageCompleted": 100.0,
16+
"ResourceTypes": [
17+
"AWS::CloudFront::CachePolicy",
18+
"AWS::CloudFront::OriginRequestPolicy",
19+
"AWS::EC2::DHCPOptions",
20+
"AWS::EC2::InternetGateway",
21+
"AWS::EC2::KeyPair",
22+
"AWS::EC2::NetworkAcl",
23+
"AWS::EC2::NetworkInsightsPath",
24+
"AWS::EC2::NetworkInterface",
25+
"AWS::EC2::PlacementGroup",
26+
"AWS::EC2::Route",
27+
"AWS::EC2::RouteTable",
28+
"AWS::EC2::SecurityGroup",
29+
"AWS::EC2::Subnet",
30+
"AWS::EC2::SubnetCidrBlock",
31+
"AWS::EC2::SubnetNetworkAclAssociation",
32+
"AWS::EC2::SubnetRouteTableAssociation",
33+
...
34+
],
35+
"ResourcesRead": 676
36+
}
37+
38+
For more information, see `Generating templates from existing resources <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/generate-IaC.html>`__ in the *AWS CloudFormation User Guide*.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
**To describe a stack refactor operation**
2+
3+
The following ``describe-stack-refactor`` example describes the stack refactor operation with the specified stack refactor ID. ::
4+
5+
aws cloudformation describe-stack-refactor \
6+
--stack-refactor-id 9c384f70-4e07-4ed7-a65d-fee5eb430841
7+
8+
Output::
9+
10+
{
11+
"StackRefactorId": "9c384f70-4e07-4ed7-a65d-fee5eb430841",
12+
"StackIds": [
13+
"arn:aws:cloudformation:us-east-1:123456789012:stack/Stack1/3e6a1ff0-94b1-11f0-aa6f-0a88d2e03acf",
14+
"arn:aws:cloudformation:us-east-1:123456789012:stack/Stack2/5da91650-94b1-11f0-81cf-0a23500e151b"
15+
],
16+
"ExecutionStatus": "AVAILABLE",
17+
"Status": "CREATE_COMPLETE"
18+
}
19+
20+
For more information, see `Stack refactoring <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stack-refactoring.html>`__ in the *AWS CloudFormation User Guide*.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
**To complete a stack refactor operation**
2+
3+
The following ``execute-stack-refactor`` example completes the stack refactor operation with the specified stack refactor ID. ::
4+
5+
aws cloudformation execute-stack-refactor \
6+
--stack-refactor-id 9c384f70-4e07-4ed7-a65d-fee5eb430841
7+
8+
This command produces no output.
9+
10+
For more information, see `Stack refactoring <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stack-refactoring.html>`__ in the *AWS CloudFormation User Guide*.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
**To list generated templates**
2+
3+
The following ``list-generated-templates`` example lists all generated templates. ::
4+
5+
aws cloudformation list-generated-templates
6+
7+
Output::
8+
9+
{
10+
"Summaries": [
11+
{
12+
"GeneratedTemplateId": "arn:aws:cloudformation:us-east-1:123456789012:generatedtemplate/7fc8512c-d8cb-4e02-b266-d39c48344e48",
13+
"GeneratedTemplateName": "MyTemplate",
14+
"Status": "COMPLETE",
15+
"StatusReason": "All resources complete",
16+
"CreationTime": "2025-09-23T20:13:24.283000+00:00",
17+
"LastUpdatedTime": "2025-09-23T20:13:28.610000+00:00",
18+
"NumberOfResources": 4
19+
},
20+
{
21+
"GeneratedTemplateId": "arn:aws:cloudformation:us-east-1:123456789012:generatedTemplate/f10dd1c4-edc6-4823-8153-ab6112b8d051",
22+
"GeneratedTemplateName": "MyEC2InstanceTemplate",
23+
"Status": "COMPLETE",
24+
"StatusReason": "All resources complete",
25+
"CreationTime": "2024-08-08T19:35:49.790000+00:00",
26+
"LastUpdatedTime": "2024-08-08T19:35:52.207000+00:00",
27+
"NumberOfResources": 3
28+
},
29+
{
30+
"GeneratedTemplateId": "arn:aws:cloudformation:us-east-1:123456789012:generatedTemplate/e5a1c89f-7ce2-41bd-9bdf-75b7c852e3ca",
31+
"GeneratedTemplateName": "MyEKSNodeGroupTemplate",
32+
"Status": "COMPLETE",
33+
"StatusReason": "All resources complete",
34+
"CreationTime": "2024-07-16T20:39:27.883000+00:00",
35+
"LastUpdatedTime": "2024-07-16T20:39:35.766000+00:00",
36+
"NumberOfResources": 4
37+
}
38+
]
39+
}
40+
41+
For more information, see `Generating templates from existing resources <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/generate-IaC.html>`__ in the *AWS CloudFormation User Guide*.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
**To list related resources from a resource scan**
2+
3+
The following ``list-resource-scan-related-resources`` example lists resources from the specified resource scan that are related to resources in ``resources.json``. ::
4+
5+
aws cloudformation list-resource-scan-related-resources \
6+
--resource-scan-id arn:aws:cloudformation:us-east-1:123456789012:resourceScan/0a699f15-489c-43ca-a3ef-3e6ecfa5da60 \
7+
--resources file://resources.json
8+
9+
Contents of ``resources.json``::
10+
11+
[
12+
{
13+
"ResourceType": "AWS::EKS::Cluster",
14+
"ResourceIdentifier": {
15+
"ClusterName": "MyAppClusterName"
16+
}
17+
},
18+
{
19+
"ResourceType": "AWS::AutoScaling::AutoScalingGroup",
20+
"ResourceIdentifier": {
21+
"AutoScalingGroupName": "MyAppASGName"
22+
}
23+
}
24+
]
25+
26+
Output::
27+
28+
{
29+
"RelatedResources": [
30+
{
31+
"ResourceType": "AWS::EKS::Nodegroup",
32+
"ResourceIdentifier": {
33+
"NodegroupName": "MyAppNodegroupName"
34+
},
35+
"ManagedByStack": false
36+
},
37+
{
38+
"ResourceType": "AWS::IAM::Role",
39+
"ResourceIdentifier": {
40+
"RoleId": "arn:aws::iam::123456789012:role/MyAppIAMRole"
41+
},
42+
"ManagedByStack": false
43+
}
44+
]
45+
}
46+
47+
For more information, see `Create a CloudFormation template from resources scanned with IaC generator <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/iac-generator-create-template-from-scanned-resources.html>`__ in the *AWS CloudFormation User Guide*.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
**To list resources from a resource scan**
2+
3+
The following ``list-resource-scan-resources`` example lists resources from the specified resource scan, filtered by resource identifier. ::
4+
5+
aws cloudformation list-resource-scan-resources \
6+
--resource-scan-id arn:aws:cloudformation:us-east-1:123456789012:resourceScan/0a699f15-489c-43ca-a3ef-3e6ecfa5da60 \
7+
--resource-identifier MyApp
8+
9+
Output::
10+
11+
{
12+
"Resources": [
13+
{
14+
"ResourceType": "AWS::EKS::Cluster",
15+
"ResourceIdentifier": {
16+
"ClusterName": "MyAppClusterName"
17+
},
18+
"ManagedByStack": false
19+
},
20+
{
21+
"ResourceType": "AWS::AutoScaling::AutoScalingGroup",
22+
"ResourceIdentifier": {
23+
"AutoScalingGroupName": "MyAppASGName"
24+
},
25+
"ManagedByStack": false
26+
}
27+
]
28+
}
29+
30+
For more information, see `Create a CloudFormation template from resources scanned with IaC generator <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/iac-generator-create-template-from-scanned-resources.html>`__ in the *AWS CloudFormation User Guide*.

0 commit comments

Comments
 (0)