1
votes

I have a cloud formation template and everything works really well apart from creating a file on the EC2 instance as part of the LaunchConfiguration.

"AWS::CloudFormation::Init" :
    {
      "files" :
      {
          "/etc/httpd/conf.d/vhosts.conf" :
          {
            "content" : "<VirtualHost *:80> </VirtualHost>",
            "mode"    : "000644",
            "owner"   : "root",
            "group"   : "root"
          }
      }
    }

I realise this file wont work but i wanted a simple example without extra Fn:: functions involved.

Basically this file doesn't get created. It doesn't exist on the EC2 instance AMI that is part of this Launch Configuration. I thought it should be created with the specified content from the template. I know this Launch Configuration is being used as the UserData script is being executed. But the files section isn't working.

Theres also no obvious messages in cloud-init.log or cloud-init-output.log.

Im looking for pointers on either how to debug this (can i execute part of my template from the command line and see more output ?) or ideas for why this file isn't being created.

Ive had a good hunt around the web and come up empty - the syntax is pretty simple and no errors so I'm a bit stuck at the moment.

I suppose I'm assuming that the cfg-init script will have the correct access rights to write a file in /etc.

Thanks Dave

1

1 Answers

0
votes

You need to read more about how cfn-init works and how you can feed the metadata to a cloudformation stack.

Looking at your code, it seems that you are passing metadata to cloudformation. what you wrote is feeding the metadata to cloudformation.

Now you need to have this metadata executed on the instance with the help of cfn-init script.

Refer:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-init.html http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-init.html