簡體   English   中英

如何為使用自動縮放組啟動的ec2實例添加文件?

[英]How to add files for the ec2 instance which is launched with autoscaling group?

我看到我們可以使用Cloudformation:Init通過Metadata將文件添加到ec2實例,如下所示。

"Resources": {
 "MyInstance": {
"Type": "AWS::EC2::Instance",
"Metadata" : {
  "AWS::CloudFormation::Init" : {
    "config" : {
      "packages" : {
        :
      },
      "groups" : {
        :
      },
      "users" : {
        :
      },
      "sources" : {
        :
      },
      "files" : {
        :
      },
      "commands" : {
        :
      },
      "services" : {
        :
      }
    }
  }
}

}}

但是,當我要使用自動縮放組啟動實例時,該怎么辦? 我嘗試將啟動配置下的元數據添加為EC2。

在Auto Scaling組使用的AWS::AutoScaling::LaunchConfiguration資源中包括Metadata結構。

"LaunchConfig" : {
  "Type" : "AWS::AutoScaling::LaunchConfiguration",
  "Metadata" : {
    "AWS::CloudFormation::Init" : {
      "config" : {
        "files" : {
        }
      }
    }
  },
  "Properties" : {
  }
}

這里有一個樣本可以做到這一點:

https://s3.amazonaws.com/cloudformation-templates-us-east-1/AutoScalingMultiAZWithNotifications.template

看一下“ LaunchConfig”資源。

現在,它運作良好。 啟動ec2后,我可以運行cfn-int -s <stack_name> -r <resource> --region ..來同步資源。

暫無
暫無

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

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