1

From what I understand, CloudFormation template can retrieve a file from remote and run it (Ex: bash shell), for example: download a bash script to install Graphite/OpenTSDB RRD tools.

My question is: is there any best practice between using CloudFormation template commands to do installation steps by steps vs using CloudFormation template to retrieve the bash script to run installation?

Thanks

1
  • 1
    The question is confusing as currently worded. Can you provide examples of the cases you are trying to compare? Commented Oct 19, 2013 at 0:29

2 Answers 2

3

There is no "best" way to do it, there are only lots of different options with different trade-offs.

Putting scripts in your CF template quickly becomes tiresome because you have to quote your data.

Linking to shell scripts can get complex because you have to specify everything in detail, and the steps can get brittle.

After a while, you'll want to use Puppet or Chef. These let you declare what you want "Apache 2.1 should be installed, the config file should look like this.." instead of specifying how it should be done. This can keep complex things organized. (But has a learning curve. Look into OpsWorks.)

After that, you'll want to bundle your image into an AMI (speeds things up if your build take a while, and relies on other servers on the internet being up to install!)

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks @BraveNewCurrency, I have heard about Puppet and Chef but did not know what they really are used for until you explain it. I will look into these options as well.
btw, @BraveNewCurrency, I would have to pick one Puppet or Chef, any suggestion?
For anyone seeing this now, there are more options. Such as Ansible, and Saltstack.
2

I'd suggest you use user-data, given as a parameter to your template. whether it is saved locally or remotely, it is best to separate your infrastructure details (i.e the template) from the boot logic (the shell script). the user data can be a shell script, and it will get invoked when your instances boot. Here's an example of providing user-data as a parameter:

    "Parameters":{
    "KeyName":{
        "Description":"N/A",
        "Type":"String"
    },
    "initScript":{
        "Description":"The shell script to be executed on boot",
        "Type":"String"
    },
},
"Resources":{
    "workersGroup1":{
    "GlobalWorker":{
        "Type":"AWS::EC2::Instance",
        "Properties":{
            "InstanceType":"t1.micro",
            "ImageId":"ami-XXXX",
            "UserData":{"Fn::Base64":{"Fn::Join":["",   [{"Ref":"initScript"}]]}},
...

1 Comment

I figured that if I separated my initScript out into a file saved on remote and let the template retrieve the script, than I can reuse the script everywhere ele. Example: some people would like install Graphite but they don't have AWS CloudFormation. I wrote CloudFormation template to load install script remotely, here is the template script: github.com/gdbtek/cloudformation-templates/blob/master/…, github.com/gdbtek/setup-graphite/blob/master/ubuntu.bash, and github.com/gdbtek/setup-statsd/blob/master/ubuntu.bash

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.