01 Run list-stacks command (OSX/Linux/UNIX) to list the name of each Amazon CloudFormation stack available in FAILED mode, within the selected AWS region:
aws cloudformation list-stacks
--region us-east-1
--stack-status-filter "CREATE_FAILED" "DELETE_FAILED" "ROLLBACK_FAILED" "UPDATE_FAILED" "UPDATE_ROLLBACK_FAILED" "IMPORT_ROLLBACK_FAILED"
--output table
--query 'StackSummaries[*].StackName'
02 The command output should return the name(s) of the failed CloudFormation stack(s):
-----------------------------
| ListStacks |
+---------------------------+
| cc-project5-test-stack |
| cc-demo-application-stack |
+---------------------------+
03 Run describe-stacks command (OSX/Linux/UNIX) using the name of the failed CloudFormation stack that you want to examine as the identifier parameter and custom query filters to describe the events triggered for the selected stack in reverse chronological order:
aws cloudformation describe-stack-events
--region us-east-1
--stack-name cc-project5-test-stack
--query 'StackEvents'
04 The command output should return the requested event information:
[
{
"StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/cc-project5-test-stack/abcdabcd-1234-abcd-1234-abcd1234abcd",
"EventId": "WebServerSecurityGroup-CREATE_FAILED-2022-01-13T17:11:23.981Z",
"StackName": "cc-project5-test-stack",
"LogicalResourceId": "WebServerSecurityGroup",
"PhysicalResourceId": "cc-project5-test-stack-WebServerSecurityGroup-ABCDABCDABCDABCD",
"ResourceType": "AWS::EC2::SecurityGroup",
"Timestamp": "2022-01-13T17:11:23.981000+00:00",
"ResourceStatus": "CREATE_FAILED",
"ResourceProperties": "{\"GroupDescription\":\"Enable HTTP access via port 80\",\"SecurityGroupIngress\":[{\"CidrIp\":\"0.0.0.0/0\",\"FromPort\":\"80\",\"ToPort\":\"80\",\"IpProtocol\":\"tcp\"},{\"CidrIp\":\"0.0.0.0/0\",\"FromPort\":\"22\",\"ToPort\":\"22\",\"IpProtocol\":\"tcp\"}]}",
"ClientRequestToken": "Console-CreateStack-abcdabcd-1234-abcd-1234-abcd1234abcd"
},
{
"StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/cc-project5-test-stack/abcdabcd-1234-abcd-1234-abcd1234abcd",
"EventId": "WebServerSecurityGroup-CREATE_IN_PROGRESS-2022-01-13T17:11:17.471Z",
"StackName": "cc-project5-test-stack",
"LogicalResourceId": "WebServerSecurityGroup",
"PhysicalResourceId": "",
"ResourceType": "AWS::EC2::SecurityGroup",
"Timestamp": "2022-01-13T17:11:17.471000+00:00",
"ResourceStatus": "CREATE_IN_PROGRESS",
"ResourceProperties": "{\"GroupDescription\":\"Enable HTTP access via port 80\",\"SecurityGroupIngress\":[{\"CidrIp\":\"0.0.0.0/0\",\"FromPort\":\"80\",\"ToPort\":\"80\",\"IpProtocol\":\"tcp\"},{\"CidrIp\":\"0.0.0.0/0\",\"FromPort\":\"22\",\"ToPort\":\"22\",\"IpProtocol\":\"tcp\"}]}",
"ClientRequestToken": "Console-CreateStack-abcdabcd-1234-abcd-1234-abcd1234abcd"
},
{
"StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/cc-project5-test-stack/abcdabcd-1234-abcd-1234-abcd1234abcd",
"EventId": "abcdabcd-1234-abcd-1234-abcd1234abcd",
"StackName": "cc-project5-test-stack",
"LogicalResourceId": "cc-project5-test-stack",
"PhysicalResourceId": "arn:aws:cloudformation:us-east-1:123456789012:stack/cc-project5-test-stack/abcdabcd-1234-abcd-1234-abcd1234abcd",
"ResourceType": "AWS::CloudFormation::Stack",
"Timestamp": "2022-01-13T17:11:10.497000+00:00",
"ResourceStatus": "CREATE_IN_PROGRESS",
"ResourceStatusReason": "User Initiated",
"ClientRequestToken": "Console-CreateStack-abcdabcd-1234-abcd-1234-abcd1234abcd"
}
]
Check the
"Timestamp" property value listed for the failed stack event (highlighted) to determine when the event occurred and switched on the
FAILED mode. Based on the timestamp returned, if the
FAILED mode was triggered more than 6 hours ago, the selected Amazon CloudFormation stack is considered unsuccessful and can be removed from your AWS account.
05 Repeat steps no. 3 and 4 for each failed Amazon CloudFormation stack available in the selected AWS region.
06 Change the AWS cloud region by updating the --region command parameter value and repeat the Audit process for other regions.