简体   繁体   中英

Is it possible to use AWS::CloudFormation::Init and metadata in AWS::OpsWorks::Instance resource?

I want to create a stack by opsworks and I want to configure user data in my stack instances. I'm not going to need an auto scaling group, so is it possible to use metadata and AWS::CloudFormation::Init in an AWS::OpsWorks::Instance resource the way we do in AWS::EC2::Instance and launch configuration?

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

TLDR: Use Chef recipes and cookbooks to configure an AWS::OpsWorks::Instance , not cfn-init .

Internally, OpsWorks uses cloud-init to install the AWS OpsWorks Stacks agent on the instance (see Using Custom AMIs: Startup Behavior ). Presumably for this reason, setting a custom user-data script is not supported on OpsWorks instances, so you can't run cfn-init on startup the same way you can on regular AWS::EC2::Instance resources.

For a workaround, you could use a custom AMI for your instance and configure the AMI to invoke cfn-init on startup.

However, a workaround like that is strongly discouraged- you really shouldn't ever need to use cfn-init (or its corresponding AWS::CloudFormation::Init metadata) in an OpsWorks stack to begin with. cfn-init is entirely orthogonal to the much more robust Chef-based configuration management that OpsWorks provides, which is presumably the reason you're using OpsWorks in the first place. Take advantage of it! Use Chef recipes and cookbooks to configure your instance.

If you really need to use cfn-init and custom user-data (to support legacy code, for example), then I'd recommend sticking to standard EC2 instances until you can port your application logic over to custom Chef cookbooks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM