Create a gist now

Instantly share code, notes, and snippets.

Ubuntu CloudFormation Tools installation snippet. Modified version of
"UserData": {
"Fn::Base64": { "Fn::Join":["", [
"#!/bin/bash -ex\n",
"apt-get update\n",
"apt-get -y install python-setuptools\n",
"mkdir aws-cfn-bootstrap-latest\n",
"curl | 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",
"/usr/local/bin/cfn-signal --exit-code $? '", { "Ref" : "WaitHandle" }, "'\n"

I got this working by adding a comma at the end of line 9 and defining the "WaitHandle" earlier in the template.

kixorz commented Oct 5, 2015

Thanks! I'll update it.


Another example which uses pip instead of easy_install and works behind a proxy:

    "UserData": {
          "Fn::Base64": {
            "Fn::Join": ["", [
              "set -o errexit; set -o nounset; set -o pipefail\n",
              "echo 'Acquire::http::proxy \" \";' > /etc/apt/apt.conf.d/80proxy\n",
              "echo 'Acquire::https::proxy \" \";' >> /etc/apt/apt.conf.d/80proxy\n",

              "# Install AWS cfn-bootstrap utilities\n",
              "apt-get update\n",
              "apt-get -y install python-pip\n",
              "pip install --proxy\n",

              " --stack ", { "Ref": "AWS::StackName" },
              " --resource MyLogicalResourceName",
              " --configsets bootstrap-chef",
              " --region ", { "Ref": "AWS::Region" }, "\n"

Another more basic example with easy install for Debian 8.

    "UserData": {
      "Fn::Base64": { "Fn::Join":["", [
        "apt-get update\n",
        "apt-get -y install python-setuptools\n",
        "cfn-init --stack ", { "Ref": "AWS::StackName" }," --resource LaunchConfig --region ", { "Ref": "AWS::Region" }, "\n",
        "cfn-signal -e $? ","--stack ", { "Ref": "AWS::StackName" }," --resource WebServerGroup --region ", { "Ref": "AWS::Region" }, "\n"
wtfiwtz commented Oct 12, 2016 edited

On Ubuntu 16.04.1 LTS this works:

#!/bin/bash -xe

mkdir -p /tmp/aws-cfn-bootstrap-latest

curl | tar xz -C /tmp/aws-cfn-bootstrap-latest --strip-components 1

curl -o /etc/systemd/system/cfn-hup.service

apt-get update

apt-get install -y python-pip libssl-dev libffi-dev

pip install pyopenssl ndg-httpsclient pyasn1

pip install --upgrade /tmp/aws-cfn-bootstrap-latest

cp /tmp/aws-cfn-bootstrap-latest/init/ubuntu/cfn-hup /etc/init.d/cfn-hup
update-rc.d cfn-hup defaults
chmod 755 /etc/init.d/cfn-hup

A sample cfn-hup.service file is here: adamreeve/

... although you might need to set the launch path to /usr/local/bin/cfn-hup

Another issue was that I had to disable the cfn-hup service setup - maybe Cloudformation's cloud-init and cfn-init is not compatible with systemd. You can install the upstart-sysv Ubuntu package to switch back to upstart although I had other difficulties with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment