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.