amazon web services - AWS::CloudFormation::Init not executing commands in metadata -
this template test command in metadata. can't figure out why command doesn't executed. it's supposed save string file in /tmp. machine ubuntu 16.04 cloud-init installed. in userdata install helper scripts , execute cfn-init.
thanks help.
{ "awstemplateformatversion": "2010-09-09", "metadata": { "aws::cloudformation::designer": { "2af5b799-f6bf-7f20-a6eb-943274f18373": { "size": { "width": 60, "height": 60 }, "position": { "x": 326, "y": 118 }, "z": 0, "embeds": [] } } }, "resources": { "ec2i3wadd": { "type": "aws::ec2::instance", "properties": { "imageid": "ami-c60b90d1", "keyname": "cf-key", "instancetype": "t2.micro", "userdata": { "fn::base64": { "fn::join": [ "", [ "#!/bin/bash -xe\n", "apt-get -y install python-setuptools\n", "mkdir aws-cfn-bootstrap-latest\n", "curl https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz | tar xz -c aws-cfn-bootstrap-latest --strip-components 1\n", "easy_install aws-cfn-bootstrap-latest\n", "/usr/local/bin/cfn-init --stack ", { "ref": "aws::stackname" }, " --resource webserver", " --region ", { "ref": "aws::region" }, "\n" ] ] } } }, "metadata": { "aws::cloudformation::designer": { "id": "2af5b799-f6bf-7f20-a6eb-943274f18373" }, "aws::cloudformation::init": { "config": { "commands": { "test": { "command": "echo \"$magic\" > /tmp/test.txt", "env": { "magic": "i come environment!" } } } } } } } } }
the issue being cause incorrect --resource
argument being passed cfn-init command within userdata. argument should match logical resource name of resource containing metadata, in case ec2i3wadd
.
"/usr/local/bin/cfn-init --stack ", { "ref": "aws::stackname" }, " --resource ec2i3wadd", " --region ", { "ref": "aws::region" }
https://docs.aws.amazon.com/awscloudformation/latest/userguide/cfn-init.html
Comments
Post a Comment