2

Up until now I've been launching EC2 instances manually, copying over a bash script that downloads my chef + chef artifacts, and calls chef-solo to provision an instance.

A former AWS engineer in the company had at one point created CF templates; which I barely know how to use.

Is there a way to integrate my bash script into the CF template, so that upon CF EC2 instance launch, my bash script is called and the instance is auto-provisioned?

Sam Hammamy
  • 189
  • 5
  • 17

1 Answers1

9

Yes, you can use the UserData attribute of your AWS::EC2::Instance object.

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html#cfn-ec2-instance-userdata

This attribute takes as input the base64-encoded version of your shell script. You can, however, provide the script inline with the help of a Cloudformation Base64 function:

"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
    "#!/bin/bash -v\n",
    "# Script goes here\n"
]]}}
EEAA
  • 109,363
  • 18
  • 175
  • 245