Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm very new to the AWS services. I'm trying to use the AWS cloud formation and I created a template. The template is error free and I am able to create machines using that.

But I have added some config in the template such that it installs tomcat, git and other things during startup. But that doesn't happen for me.

Here is a part of code I used for installing tomcat :

"Resources": {
    "Tomcat": {
        "Type": "AWS::EC2::Instance",
        "Metadata": {
            "AWS::CloudFormation::Init": {
                "config": {
                    "packages": {
                        "apt": {
                            "tomcat6": [],
                            "git": [],
                        }
                    }
                }
            }
        },

But when I log into the machine neither tomcat nor git have been installed!

Thanks in advance.

share|improve this question
    
I assume from your tags that this is an Ubuntu AMI? –  mattdm Jan 8 '13 at 21:05
    
Have you tried to remove the "," after "git":[]? It's not syntactically correct. –  Edwin Jan 12 '13 at 9:01
    
Any solution for this? I'm also facing same issue. –  robert Jan 22 '13 at 7:22

3 Answers 3

I believe your problem here is confusion around that cloud-init is not the same as cfn-init.

  • cloud-init is the tool that started as part of the Ubuntu AWS AMIs that allow the interpretation of the EC2 user-data component of the instance meta-data. Amazon Linux adopted this tool as well and built it into their AMI.

  • cfn-init is part of a different toolset called CloudFormation Helper Scripts created by AWS for Amazon Linux that can read an additional section named Metadata in your CloudFormation template.

So, Ubuntu and Amazon Linux AMIs both have the cloud-init tools preinstalled to access the user-data, but only Amazon Linux has the CloudFormation Helper Scripts preinstalled e.g. cfn-init to access the CloudFormation Metadata.

However, AWS does distribute packages that you can use to read the CloudFormation Metadata. Specifically, look at this template for how you can use a cloud-init user-data script to install python-setuptools, download the CloudFormation Helper Scripts, install them using easy_install and then invoke cfn-init.

Note: There are other distributions or AMIs that might support cloud-init or cfn-init, but I'm just covering the general cases here.

share|improve this answer

You need to call cfn-init (http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-init.html) inside the UserData property of the instance:

"Resources": {
    "Tomcat": {
        "Type": "AWS::EC2::Instance",
        "Metadata": {
            "AWS::CloudFormation::Init": {
                "config": {
                    "packages": {
                        "apt": {
                            "tomcat6": [],
                            "git": [],
                        }
                    }
                }
            }
        },
        "Properties": {
            "UserData": {"Fn::Base64": {"Fn::Join": ["", [
                 "#!/bin/bash\n"
                 "/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" },
                 "    -r Tomcat",
                 "    --region ", { "Ref" : "AWS::Region" }, "\n",
            ]]}}
        }

The UserData property is Base64 encoded, and allows you to specify a script that should be run at instance launch. Here you can call cfn-init which will read the CloudFormation::Init Metadata and setup everything specified there.

Also when creating the CF Stack you might want to go into advanced settings on the second page (after giving the parameters) and make sure Rollback on error is set to "No". That way if the cfn-init script fails for whatever reason you can ssh onto the instance and check the /var/log/cfn-init.log file for more info.

share|improve this answer
    
I think this one should be the accepted answer. –  Erik van Brakel Jul 30 '14 at 12:26

Above answer is correct. But you also should make sure that you have sucessfully installed CloudFormation helper scripts. Please follow to http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-helper-scripts-reference.html for installation details.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.