{"id":202,"date":"2014-02-23T13:09:49","date_gmt":"2014-02-23T12:09:49","guid":{"rendered":"http:\/\/www.cymbeline.ch\/?p=202"},"modified":"2014-12-23T09:22:30","modified_gmt":"2014-12-23T08:22:30","slug":"using-cloud-init-to-auto-deploy-new-ec2-instances","status":"publish","type":"post","link":"https:\/\/cymbeline.ch\/2014\/02\/23\/using-cloud-init-to-auto-deploy-new-ec2-instances\/","title":{"rendered":"Using Cloud-Init to Auto-Deploy New EC2 Instances"},"content":{"rendered":"

So you have a machine role that you’re auto-scaling in AWS and you want new EC2 instances to initialize automatically after their creation? Cloud-init<\/a> is here to help; it let’s you manage and configure many aspects of the machine (like installing the latest updates or missing packages). It also let’s you run any commands you want. So what else would you need to get your own bits installed? That’s right, nothing!<\/p>\n

\r\n#cloud-config\r\n# Update existing packages\r\napt_update: true\r\n\r\n# Install more packages\r\npackages:\r\n- tomcat7\r\n- jq\r\n\r\n# Download the latest bits from S3, extract and setup.\r\nruncmd:\r\n- aws s3api get-object --bucket my-bits --key latest\/mybits.tar.gz mybits.tar.gz\r\n- mkdir mybits\r\n- tar xvzf mybits.tar.gz -C mybits\r\n- bash mybits\/my-own-setup-script.sh\r\n<\/pre>\n

In this case, the script my-own-setup-script.sh<\/code> is run at the end of initialization and can make sure to deploy everything as required. All you need to do, is push a package with the latest bits onto S3 and all new instances for this role will automatically get the latest bits installed when they are created. Of course you’ll need to make sure that the machine’s IAM role is allowed access to the corresponding S3 bucket and file.<\/p>\n

<\/p>","protected":false},"excerpt":{"rendered":"

So you have a machine role that you’re auto-scaling in AWS and you want new EC2 instances to initialize automatically after their creation? Cloud-init is here to help; it let’s you manage and configure many aspects of the machine (like installing the latest updates or missing packages). It also let’s you run any commands you … Continue reading “Using Cloud-Init to Auto-Deploy New EC2 Instances”<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[61],"tags":[67,69,68,70],"yoast_head":"\nInitialize EC2 Instances with Cloud-init<\/title>\n<meta name=\"description\" content=\"Use Cloud-init to initialize AWS EC2 Instances after Creation.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cymbeline.ch\/2014\/02\/23\/using-cloud-init-to-auto-deploy-new-ec2-instances\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Initialize EC2 Instances with Cloud-init\" \/>\n<meta property=\"og:description\" content=\"Use Cloud-init to initialize AWS EC2 Instances after Creation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cymbeline.ch\/2014\/02\/23\/using-cloud-init-to-auto-deploy-new-ec2-instances\/\" \/>\n<meta property=\"og:site_name\" content=\"Tales of a Code Monkey\" \/>\n<meta property=\"article:published_time\" content=\"2014-02-23T12:09:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-12-23T08:22:30+00:00\" \/>\n<meta name=\"author\" content=\"roger\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"roger\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cymbeline.ch\/2014\/02\/23\/using-cloud-init-to-auto-deploy-new-ec2-instances\/\",\"url\":\"https:\/\/cymbeline.ch\/2014\/02\/23\/using-cloud-init-to-auto-deploy-new-ec2-instances\/\",\"name\":\"Initialize EC2 Instances with Cloud-init\",\"isPartOf\":{\"@id\":\"https:\/\/cymbeline.ch\/#website\"},\"datePublished\":\"2014-02-23T12:09:49+00:00\",\"dateModified\":\"2014-12-23T08:22:30+00:00\",\"author\":{\"@id\":\"https:\/\/cymbeline.ch\/#\/schema\/person\/cf1f3b3205f4266bf8b68a80fa6b0916\"},\"description\":\"Use Cloud-init to initialize AWS EC2 Instances after Creation.\",\"breadcrumb\":{\"@id\":\"https:\/\/cymbeline.ch\/2014\/02\/23\/using-cloud-init-to-auto-deploy-new-ec2-instances\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cymbeline.ch\/2014\/02\/23\/using-cloud-init-to-auto-deploy-new-ec2-instances\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cymbeline.ch\/2014\/02\/23\/using-cloud-init-to-auto-deploy-new-ec2-instances\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cymbeline.ch\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using Cloud-Init to Auto-Deploy New EC2 Instances\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cymbeline.ch\/#website\",\"url\":\"https:\/\/cymbeline.ch\/\",\"name\":\"Tales of a Code Monkey\",\"description\":\"... the adventures of a guy making software.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cymbeline.ch\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/cymbeline.ch\/#\/schema\/person\/cf1f3b3205f4266bf8b68a80fa6b0916\",\"name\":\"roger\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cymbeline.ch\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/33cc08db99ae52beb26ab6fda46e0eb7?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/33cc08db99ae52beb26ab6fda46e0eb7?s=96&r=g\",\"caption\":\"roger\"},\"sameAs\":[\"https:\/\/www.cymbeline.ch\"],\"url\":\"https:\/\/cymbeline.ch\/author\/roger\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Initialize EC2 Instances with Cloud-init","description":"Use Cloud-init to initialize AWS EC2 Instances after Creation.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cymbeline.ch\/2014\/02\/23\/using-cloud-init-to-auto-deploy-new-ec2-instances\/","og_locale":"en_US","og_type":"article","og_title":"Initialize EC2 Instances with Cloud-init","og_description":"Use Cloud-init to initialize AWS EC2 Instances after Creation.","og_url":"https:\/\/cymbeline.ch\/2014\/02\/23\/using-cloud-init-to-auto-deploy-new-ec2-instances\/","og_site_name":"Tales of a Code Monkey","article_published_time":"2014-02-23T12:09:49+00:00","article_modified_time":"2014-12-23T08:22:30+00:00","author":"roger","twitter_misc":{"Written by":"roger","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/cymbeline.ch\/2014\/02\/23\/using-cloud-init-to-auto-deploy-new-ec2-instances\/","url":"https:\/\/cymbeline.ch\/2014\/02\/23\/using-cloud-init-to-auto-deploy-new-ec2-instances\/","name":"Initialize EC2 Instances with Cloud-init","isPartOf":{"@id":"https:\/\/cymbeline.ch\/#website"},"datePublished":"2014-02-23T12:09:49+00:00","dateModified":"2014-12-23T08:22:30+00:00","author":{"@id":"https:\/\/cymbeline.ch\/#\/schema\/person\/cf1f3b3205f4266bf8b68a80fa6b0916"},"description":"Use Cloud-init to initialize AWS EC2 Instances after Creation.","breadcrumb":{"@id":"https:\/\/cymbeline.ch\/2014\/02\/23\/using-cloud-init-to-auto-deploy-new-ec2-instances\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cymbeline.ch\/2014\/02\/23\/using-cloud-init-to-auto-deploy-new-ec2-instances\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cymbeline.ch\/2014\/02\/23\/using-cloud-init-to-auto-deploy-new-ec2-instances\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cymbeline.ch\/"},{"@type":"ListItem","position":2,"name":"Using Cloud-Init to Auto-Deploy New EC2 Instances"}]},{"@type":"WebSite","@id":"https:\/\/cymbeline.ch\/#website","url":"https:\/\/cymbeline.ch\/","name":"Tales of a Code Monkey","description":"... the adventures of a guy making software.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cymbeline.ch\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/cymbeline.ch\/#\/schema\/person\/cf1f3b3205f4266bf8b68a80fa6b0916","name":"roger","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cymbeline.ch\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/33cc08db99ae52beb26ab6fda46e0eb7?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/33cc08db99ae52beb26ab6fda46e0eb7?s=96&r=g","caption":"roger"},"sameAs":["https:\/\/www.cymbeline.ch"],"url":"https:\/\/cymbeline.ch\/author\/roger\/"}]}},"_links":{"self":[{"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/posts\/202"}],"collection":[{"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/comments?post=202"}],"version-history":[{"count":9,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/posts\/202\/revisions"}],"predecessor-version":[{"id":270,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/posts\/202\/revisions\/270"}],"wp:attachment":[{"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/media?parent=202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/categories?post=202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/tags?post=202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}