CloudFormation
Glossary
A Stack is the name for the definition of a collection of Stack Resources that will be managed as a logical group.
A Stack Instance is the name for a running collection of Stack Resources as defined by a Stack
A Stack Set is a collection of Stacks
A CloudFormation Template is a JSON or YAML formatted file which defines the AWS Resources that make up a Stack
A Changet is a user proposed set of changes to the running resources in a Cloudformation stack.
Check
aws cloudformation list-stacks --output yaml
You can output as table but the table tends to be very wide and therefore difficult to readaws cloudformation describe-stacks --output yaml
You can output as table but the table tends to be very wide and therefore difficult to readIf you have forgotten the name of your stack, use this command to help find it...
aws cloudformation describe-stacks --output yaml | grep StackName
For further stack information use...
aws cloudformation describe-stacks --stack-name ${mystack}
aws cloudformation describe-stack-resources --stack-name ${mystack} --output table
See Also
Template
Stack Template Components
Template Version (Optional)
Description (Optional)
Metadata (Optional)
Parameters (Optional)
Mappings (Optional)
Conditions (Optional)
Transform (Optional)
Resources (Required)
Outputs (Optional)
Stack Template Notes
AllowedPattern
The idea is to validate correct formatting of parameters using regular expressions. Some examples include...
Basic email address structure...
^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$
A valid IPv4 IP Address structure...
^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$
Valid CIDR Block for use with AWS VPC and associated resources...
^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\/([1-2][6-9]|3[0-2]))?$
Passphrase Complexity Check (must start with a letter and minimum length of 12 alphanumeric characters including special characters)...
^[A-Za-z][a-zA-Z0-9@%$_-]{12,}$
Valid cron schedule...
^\s*($|#|\w+\s*=|(\?|\*|(?:[0-5]?\d)(?:(?:-|\/|\,)(?:[0-5]?\d))?(?:,(?:[0-5]?\d)(?:(?:-|\/|\,)(?:[0-5]?\d))?)*)\s+(\?|\*|(?:[0-5]?\d)(?:(?:-|\/|\,)(?:[0-5]?\d))?(?:,(?:[0-5]?\d)(?:(?:-|\/|\,)(?:[0-5]?\d))?)*)\s+(\?|\*|(?:[01]?\d|2[0-3])(?:(?:-|\/|\,)(?:[01]?\d|2[0-3]))?(?:,(?:[01]?\d|2[0-3])(?:(?:-|\/|\,)(?:[01]?\d|2[0-3]))?)*)\s+(\?|\*|(?:0?[1-9]|[12]\d|3[01])(?:(?:-|\/|\,)(?:0?[1-9]|[12]\d|3[01]))?(?:,(?:0?[1-9]|[12]\d|3[01])(?:(?:-|\/|\,)(?:0?[1-9]|[12]\d|3[01]))?)*)\s+(\?|\*|(?:[1-9]|1[012])(?:(?:-|\/|\,)(?:[1-9]|1[012]))?(?:L|W)?(?:,(?:[1-9]|1[012])(?:(?:-|\/|\,)(?:[1-9]|1[012]))?(?:L|W)?)*|\?|\*|(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(?:(?:-)(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))?(?:,(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(?:(?:-)(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))?)*)\s+(\?|\*|(?:[0-6])(?:(?:-|\/|\,|#)(?:[0-6]))?(?:L)?(?:,(?:[0-6])(?:(?:-|\/|\,|#)(?:[0-6]))?(?:L)?)*|\?|\*|(?:MON|TUE|WED|THU|FRI|SAT|SUN)(?:(?:-)(?:MON|TUE|WED|THU|FRI|SAT|SUN))?(?:,(?:MON|TUE|WED|THU|FRI|SAT|SUN)(?:(?:-)(?:MON|TUE|WED|THU|FRI|SAT|SUN))?)*)(|\s)+(\?|\*|(?:|\d{4})(?:(?:-|\/|\,)(?:|\d{4}))?(?:,(?:|\d{4})(?:(?:-|\/|\,)(?:|\d{4}))?)*))$
Note also that for cron scheduling in AWS You cannot use * in both the Day-of-month and Day-of-week fields. If you use it in one, you must use ? in the other.Troubleshooting Stack Updates
Check the Status reason column in the Events tab of your Stack
Example: Incorrectly formatted cron schedule...
Status reason shows...
Parameter ScheduleExpression is not valid. (Service: AmazonCloudWatchEvents; Status Code: 400; Error Code: ValidationException; Request ID: 21d36604-8adb-4773-a0b2-d69b59cae404)
Entered string matched template AllowedPattern (validated at regex101).
Google search revealed that "You cannot use * in both the Day-of-month and Day-of-week fields. If you use it in one, you must use ? in the other." In fact one or the other must always be ?. Initial setting was 5 9 * * 4 * working setting is 5 9 ? * 4 *
https://stackoverflow.com/questions/39482314/parameter-scheduleexpression-is-not-valid https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.htmlDelete Stack
From the Cloudformation console...
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-delete-stack.htmlFrom the AWS CLI...
aws cloudformation delete-stack --stack-name mystack
To delete a stack with dependencies that can't be deleted...
From the Cloudformation console...
From the AWS CLI...
aws cloudformation delete-stack --stack-name my-stack --retain-resources myresource1 myresource2
Drift Detection
aws cloudformation detect-stack-drift --stack-name mystack
Bibliography
https://aws.amazon.com/cloudformation/https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-whatis-howdoesitwork.html https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/best-practices.html https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/gettingstarted.templatebasics.html https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-cli-creating-stack.html https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/troubleshooting.html https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-concepts.html
https://confluence.atlassian.com/jirakb/use-the-jira-config-properties-file-to-customize-an-aws-quick-start-deployment-993922385.html
https://www.1strategy.com/blog/2020/01/16/leveraging-cloudformation-parameter-constraints-to-enforce-resource-configuration/ https://regex101.com/
https://stackoverflow.com/questions/39482314/parameter-scheduleexpression-is-not-valid
Designerhttps://eu-west-2.console.aws.amazon.com/cloudformation/designer/home
Delete Stackhttps://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-delete-stack.htmlhttps://repost.aws/knowledge-center/cloudformation-stack-delete-failed
Quickstartshttps://aws.amazon.com/quickstart/https://docs.aws.amazon.com/quickstarts/latest/s3backup/step-1-create-bucket.htmlhttps://aws-quickstart.github.io/option1.html
Drift Detectionhttps://dzone.com/articles/introduction-to-aws-cloudformation-drift-detection https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-stack-drift.html
Logshttps://aws.amazon.com/blogs/devops/view-cloudformation-logs-in-the-console/