cfn-init for cloud formation 启动模板
cfn-init for cloudformation launchtemplate
如何在 LaunchTemplate 中使用 cfn-init?这适用于 EC2 实例,在自动缩放组中,用于 ECS 集群。
实例的 Metadata
部分去哪里以及要传递给 cnf-init 的 --resource
是什么?
LaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateName: !Sub ${AWS::StackName}-launch-template
LaunchTemplateData:
SecurityGroups:
- !Ref DMZSecurityGroup
- !Ref ECSSecurityGroup
UserData:
Fn::Base64:
!Sub |
#!/bin/bash -xe
yum update -y aws-cfn-bootstrap
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource ??? --region ${AWS::Region}
yum -y update
我对元数据的最佳猜测产生了错误:
Property validation failure: [Encountered unsupported properties in {/LaunchTemplateData}: [Metadata]]
cfn-init
仅当您在 cloudformation 模板本身中为您的实例定义一些初始化步骤时才应使用。
cfn-init
脚本告诉 cloudformation 从模板定义(AWS::CloudFormation::Init
部分)读取您的配置步骤,并在实例上 'execute' 它们。
您还可以通过在用户数据部分传递 shell 脚本来 bootstrap 您的实例。
在您的情况下,由于我看不到您的 YAML 文件中定义的任何 bootstrap 配置步骤,因此无需在您的用户数据脚本中调用 cfn-init
。
关于 cfn-init
的更多信息:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-init.html
关于 AWS::CloudFormation::Init
的更多信息:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-init.html
我的元数据嵌套级别错误,它应该与 Type:
和 Properties:
一起处于最顶层,而不是在 Properties:LaunchTemplateData:
.
之下
LaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Metadata:
AWS::CloudFormation::Init:
config:
files:
/var/www/html/index2.html:
content: TestString
Properties:
LaunchTemplateData:
SecurityGroupIds:
- !GetAtt DMZSecurityGroup.GroupId
- !GetAtt ECSSecurityGroup.GroupId
UserData:
Fn::Base64:
!Sub |
#!/bin/bash -xe
yum update -y aws-cfn-bootstrap
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource ECSLaunchTemplate --region ${AWS::Region}
yum -y update
如何在 LaunchTemplate 中使用 cfn-init?这适用于 EC2 实例,在自动缩放组中,用于 ECS 集群。
实例的 Metadata
部分去哪里以及要传递给 cnf-init 的 --resource
是什么?
LaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateName: !Sub ${AWS::StackName}-launch-template
LaunchTemplateData:
SecurityGroups:
- !Ref DMZSecurityGroup
- !Ref ECSSecurityGroup
UserData:
Fn::Base64:
!Sub |
#!/bin/bash -xe
yum update -y aws-cfn-bootstrap
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource ??? --region ${AWS::Region}
yum -y update
我对元数据的最佳猜测产生了错误:
Property validation failure: [Encountered unsupported properties in {/LaunchTemplateData}: [Metadata]]
cfn-init
仅当您在 cloudformation 模板本身中为您的实例定义一些初始化步骤时才应使用。
cfn-init
脚本告诉 cloudformation 从模板定义(AWS::CloudFormation::Init
部分)读取您的配置步骤,并在实例上 'execute' 它们。
您还可以通过在用户数据部分传递 shell 脚本来 bootstrap 您的实例。
在您的情况下,由于我看不到您的 YAML 文件中定义的任何 bootstrap 配置步骤,因此无需在您的用户数据脚本中调用 cfn-init
。
关于 cfn-init
的更多信息:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-init.html
关于 AWS::CloudFormation::Init
的更多信息:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-init.html
我的元数据嵌套级别错误,它应该与 Type:
和 Properties:
一起处于最顶层,而不是在 Properties:LaunchTemplateData:
.
LaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Metadata:
AWS::CloudFormation::Init:
config:
files:
/var/www/html/index2.html:
content: TestString
Properties:
LaunchTemplateData:
SecurityGroupIds:
- !GetAtt DMZSecurityGroup.GroupId
- !GetAtt ECSSecurityGroup.GroupId
UserData:
Fn::Base64:
!Sub |
#!/bin/bash -xe
yum update -y aws-cfn-bootstrap
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource ECSLaunchTemplate --region ${AWS::Region}
yum -y update