AWS AWSCloudFormation documentation change
Summary
Improved formatting and structure of CloudFormation examples (JSON/YAML) for lifecycle hooks documentation
Security assessment
Changes only reformat existing template examples with proper indentation and line breaks without modifying security-related content. No security vulnerabilities addressed or new security features documented - maintains existing security elements like SecurityGroupIds and KeyName references without changes to their implementation.
Diff
diff --git a/AWSCloudFormation/latest/TemplateReference/aws-resource-autoscaling-lifecyclehook.md b/AWSCloudFormation/latest/TemplateReference/aws-resource-autoscaling-lifecyclehook.md index 015d75bd8..a54251e66 100644 --- a//AWSCloudFormation/latest/TemplateReference/aws-resource-autoscaling-lifecyclehook.md +++ b//AWSCloudFormation/latest/TemplateReference/aws-resource-autoscaling-lifecyclehook.md @@ -195,16 +195,73 @@ The example bash script in the user data customizes the hostname on instances to - { "AWSTemplateFormatVersion": "2010-09-09", "Parameters": { "LatestAmiId": { "Description": - "Region specific image from the Parameter Store", "Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>", - "Default": "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2" }, "InstanceType": { "Description": - "Amazon EC2 instance type for the instances", "Type": "String", "AllowedValues": [ "t3.micro", "t3.small", - "t3.medium" ], "Default": "t3.micro" }, "Subnets": { "Type": "CommaDelimitedList" } }, "Resources": { - "myAppLaunchTemplate": { "Type": "AWS::EC2::LaunchTemplate", "Properties": { "LaunchTemplateName": { "Fn::Sub": - "${AWS::StackName}-launch-template" }, "LaunchTemplateData": { "ImageId": { "Ref": "LatestAmiId" }, "InstanceType": - { "Ref": "InstanceType" }, "KeyName": "MyKeyPair", "SecurityGroupIds": [ "sg-083cd3bfb8example" ], "UserData": - {"Fn::Base64": {"Fn::Join": [ "", [ "#!/usr/bin/env bash\n", "set -e\n", "export INSTANCE_ID=$(curl -sLf - http://169.254.169.254/latest/meta-data/instance-id)", "\n", "export - NEW_HOSTNAME=\"${LaunchTemplateName}-$INSTANCE_ID\"", "\n", "hostname $NEW_HOSTNAME", "\n" ]]}} } } }, "myASG": { - "Type": "AWS::AutoScaling::AutoScalingGroup", "Properties": { "LaunchTemplate": { "LaunchTemplateId": { "Ref": - "myAppLaunchTemplate" }, "Version": { "Fn::GetAtt": [ "myAppLaunchTemplate", "DefaultVersionNumber" ] } }, - "MaxSize": 10, "MinSize": 1, "VPCZoneIdentifier": { "Ref": "Subnets" }, "LifecycleHookSpecificationList": [ { - "LifecycleTransition": "autoscaling:EC2_INSTANCE_LAUNCHING", "LifecycleHookName": "myLaunchLifecycleHook", - "DefaultResult": "CONTINUE", "HeartbeatTimeout": 60 } ] } } } } + { + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": { + "LatestAmiId": { + "Description": "Region specific image from the Parameter Store", + "Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>", + "Default": "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2" + }, + "InstanceType": { + "Description": "Amazon EC2 instance type for the instances", + "Type": "String", + "AllowedValues": [ + "t3.micro", + "t3.small", + "t3.medium" + ], + "Default": "t3.micro" + }, + "Subnets": { + "Type": "CommaDelimitedList" + } + }, + "Resources": { + "myAppLaunchTemplate": { + "Type": "AWS::EC2::LaunchTemplate", + "Properties": { + "LaunchTemplateName": { "Fn::Sub": "${AWS::StackName}-launch-template" }, + "LaunchTemplateData": { + "ImageId": { "Ref": "LatestAmiId" }, + "InstanceType": { "Ref": "InstanceType" }, + "KeyName": "MyKeyPair", + "SecurityGroupIds": [ "sg-083cd3bfb8example" ], + "UserData": {"Fn::Base64": {"Fn::Join": [ "", [ + "#!/usr/bin/env bash\n", + "set -e\n", + "export INSTANCE_ID=$(curl -sLf http://169.254.169.254/latest/meta-data/instance-id)", "\n", + "export NEW_HOSTNAME=\"${LaunchTemplateName}-$INSTANCE_ID\"", "\n", + "hostname $NEW_HOSTNAME", "\n" + ]]}} + } + } + }, + "myASG": { + "Type": "AWS::AutoScaling::AutoScalingGroup", + "Properties": { + "LaunchTemplate": { + "LaunchTemplateId": { + "Ref": "myAppLaunchTemplate" + }, + "Version": { + "Fn::GetAtt": [ + "myAppLaunchTemplate", + "DefaultVersionNumber" + ] + } + }, + "MaxSize": 10, + "MinSize": 1, + "VPCZoneIdentifier": { + "Ref": "Subnets" + }, + "LifecycleHookSpecificationList": [ + { + "LifecycleTransition": "autoscaling:EC2_INSTANCE_LAUNCHING", + "LifecycleHookName": "myLaunchLifecycleHook", + "DefaultResult": "CONTINUE", + "HeartbeatTimeout": 60 + } + ] + } + } + } + } @@ -215,13 +272,48 @@ The example bash script in the user data customizes the hostname on instances to - AWSTemplateFormatVersion: 2010-09-09 Parameters: LatestAmiId: Description: Region specific - image from the Parameter Store Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>' Default: - '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2' InstanceType: Description: Amazon EC2 instance type - for the instances Type: String AllowedValues: - t3.micro - t3.small - t3.medium Default: t3.micro Subnets: Type: - CommaDelimitedList Resources: myAppLaunchTemplate: Type: AWS::EC2::LaunchTemplate Properties: LaunchTemplateName: - !Sub ${AWS::StackName}-launch-template LaunchTemplateData: ImageId: !Ref LatestAmiId InstanceType: !Ref InstanceType - KeyName: MyKeyPair SecurityGroupIds: - sg-083cd3bfb8example UserData: Fn::Base64: !Sub | #!/usr/bin/env bash set -e - export INSTANCE_ID=$(curl -sLf http://169.254.169.254/latest/meta-data/instance-id) export - NEW_HOSTNAME="${LaunchTemplateName}-$INSTANCE_ID" hostname $NEW_HOSTNAME myASG: Type: - AWS::AutoScaling::AutoScalingGroup Properties: LaunchTemplate: LaunchTemplateId: !Ref myAppLaunchTemplate Version: - !GetAtt myAppLaunchTemplate.DefaultVersionNumber MaxSize: '10' MinSize: '1' VPCZoneIdentifier: !Ref Subnets - LifecycleHookSpecificationList: - LifecycleTransition: autoscaling:EC2_INSTANCE_LAUNCHING LifecycleHookName: - myLaunchLifecycleHook DefaultResult: CONTINUE HeartbeatTimeout: '60' + AWSTemplateFormatVersion: 2010-09-09 + Parameters: + LatestAmiId: + Description: Region specific image from the Parameter Store + Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>' + Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2' + InstanceType: + Description: Amazon EC2 instance type for the instances + Type: String + AllowedValues: + - t3.micro + - t3.small + - t3.medium + Default: t3.micro + Subnets: + Type: CommaDelimitedList + Resources: + myAppLaunchTemplate: + Type: AWS::EC2::LaunchTemplate + Properties: + LaunchTemplateName: !Sub ${AWS::StackName}-launch-template + LaunchTemplateData: + ImageId: !Ref LatestAmiId + InstanceType: !Ref InstanceType + KeyName: MyKeyPair + SecurityGroupIds: + - sg-083cd3bfb8example + UserData: + Fn::Base64: !Sub | + #!/usr/bin/env bash + set -e + export INSTANCE_ID=$(curl -sLf http://169.254.169.254/latest/meta-data/instance-id) + export NEW_HOSTNAME="${LaunchTemplateName}-$INSTANCE_ID" + hostname $NEW_HOSTNAME + myASG: + Type: AWS::AutoScaling::AutoScalingGroup + Properties: + LaunchTemplate: + LaunchTemplateId: !Ref myAppLaunchTemplate + Version: !GetAtt myAppLaunchTemplate.DefaultVersionNumber + MaxSize: '10' + MinSize: '1' + VPCZoneIdentifier: !Ref Subnets + LifecycleHookSpecificationList: + - LifecycleTransition: autoscaling:EC2_INSTANCE_LAUNCHING + LifecycleHookName: myLaunchLifecycleHook + DefaultResult: CONTINUE + HeartbeatTimeout: '60' @@ -238,3 +330,14 @@ This snippet does not include the notification target that would need to exist o - { "myTerminationLifecycleHook":{ "Type":"AWS::AutoScaling::LifecycleHook", "Properties":{ - "AutoScalingGroupName":{ "Ref":"myASG" }, "LifecycleTransition":"autoscaling:EC2_INSTANCE_TERMINATING", - "HeartbeatTimeout": 300, "DefaultResult": "CONTINUE", "NotificationMetadata": "optional metadata" } } } + { + "myTerminationLifecycleHook":{ + "Type":"AWS::AutoScaling::LifecycleHook", + "Properties":{ + "AutoScalingGroupName":{ + "Ref":"myASG" + }, + "LifecycleTransition":"autoscaling:EC2_INSTANCE_TERMINATING", + "HeartbeatTimeout": 300, + "DefaultResult": "CONTINUE", + "NotificationMetadata": "optional metadata" + } + } + } @@ -245,3 +348,9 @@ This snippet does not include the notification target that would need to exist o - --- myTerminationLifecycleHook: Type: AWS::AutoScaling::LifecycleHook Properties: - AutoScalingGroupName: !Ref myASG LifecycleTransition: autoscaling:EC2_INSTANCE_TERMINATING HeartbeatTimeout: '300' - DefaultResult: CONTINUE NotificationMetadata: optional metadata + --- + myTerminationLifecycleHook: + Type: AWS::AutoScaling::LifecycleHook + Properties: + AutoScalingGroupName: !Ref myASG + LifecycleTransition: autoscaling:EC2_INSTANCE_TERMINATING + HeartbeatTimeout: '300' + DefaultResult: CONTINUE + NotificationMetadata: optional metadata @@ -258,8 +367,56 @@ This snippet does not include the Amazon SQS queue and IAM role resources that w - { "AWSTemplateFormatVersion":"2010-09-09", "Parameters":{ "Subnets":{ - "Type":"CommaDelimitedList" } }, "Resources":{ "myASG":{ "Type":"AWS::AutoScaling::AutoScalingGroup", "Properties":{ - "MaxSize":"3", "MinSize":"1", "LaunchTemplate": { "LaunchTemplateId": { "Ref":"myLaunchTemplate" }, "Version":{ - "Ref":"myLaunchTemplateVersionNumber" } }, "VPCZoneIdentifier":{ "Ref":"Subnets" }, - "LifecycleHookSpecificationList":[ { "LifecycleTransition":"autoscaling:EC2_INSTANCE_LAUNCHING", - "LifecycleHookName":"myLaunchLifecycleHook", "HeartbeatTimeout":4800, "NotificationTargetARN":{ "Fn::GetAtt":[ - "SQS", "Arn" ] }, "RoleArn":{ "Fn::Join":[ ":", [ "arn:aws:iam:", { "Ref":"AWS::AccountId" }, "role/role-name" ] ] } - } ] } }, "SQS":{ "Type":"AWS::SQS::Queue" } } } + { + "AWSTemplateFormatVersion":"2010-09-09", + "Parameters":{ + "Subnets":{