簡體   English   中英

cfn-init for cloudformation launchtemplate

[英]cfn-init for cloudformation launchtemplate

你如何在LaunchTemplate中使用cfn-init? 這適用於ECS群集中的EC2實例,在自動縮放組中。

實例的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]]

我將元數據放在錯誤的嵌套級別,它應該與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

只有在cloudformation模板本身為您的實例定義一些初始化步驟時,才應使用cfn-init

cfn-init腳本告訴cloudformation從模板定義( AWS::CloudFormation::Init部分)讀取配置步驟,並在實例上“執行”它們。

您還可以通過在用戶數據部分中傳遞shell腳本來引導您的實例。

在您的情況下,由於我看不到YAML文件中定義的任何引導程序配置步驟,因此無需在用戶數據腳本中調用cfn-init

有關cfn-init更多信息: httpscfn-init

有關AWS::CloudFormation::Init更多信息: https AWS::CloudFormation::Init

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM