简体   繁体   中英

AWS CloudFormation bash deploy script vs template commands

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

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!)

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 (ie 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"}]]}},
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM