1
votes

In aws cloud formation I know you can update the stack by updating the json file and those changes will take affect but how could I just update the stacks packages for example yum update or apt update etc ?

Thanks in advance

1
you can add these commands in user data, when create new instance in cloudformation template.BMW
that's fine on creation but if I update the stack will it not go through all the user data and for example clone the repo again and install packages I already have. how does it know only to do certain things on an update >Oliver Bayes-Shelton
you need cfn-init to refresh the service. now I know how to answer your question.BMW
you able to give me an example of how to do it with initial setup and update ?Oliver Bayes-Shelton
See my answer, if you have any questions, let me know.BMW

1 Answers

2
votes

Here is the sample for you on how to handle your problem.

Update the code in Cloudformation template in userdata.

 "UserData"       : { "Fn::Base64" : { "Fn::Join" : ["", [
             "yum update -y \n",

             "# Install the files and packages from the metadata\n",
             "/opt/aws/bin/cfn-init -v ",
             "         --stack ", { "Ref" : "AWS::StackName" },
             "         --resource WebServerInstance ",
             "         --configsets InstallAndRun ",
             "         --region ", { "Ref" : "AWS::Region" }, "\n"
        ]]}}

If you need know cfn-init, read this url cfn-init

If you need a sample template, see here: Deploying Applications on Amazon EC2 with AWS CloudFormation