{"id":18601,"date":"2015-03-26T19:06:56","date_gmt":"2015-03-26T13:36:56","guid":{"rendered":"https:\/\/tothenewco.pro\/blog\/?p=18601"},"modified":"2015-06-23T13:57:09","modified_gmt":"2015-06-23T08:27:09","slug":"creating-amis-based-on-tags","status":"publish","type":"post","link":"https:\/\/tothenewco.pro\/blog\/creating-amis-based-on-tags\/","title":{"rendered":"Creating AMIs based on Tags"},"content":{"rendered":"<p>You must be wondering how to make AMI of the Web Server(EC2 instance) in which you have made some changes. In this blog I will walk you through a script that will ease up your work and make AMI of instances with user specified tags.<\/p>\n<p>Consider a use-case where user has made some changes to the Web Server and he wants to take AMI according to the tags specified to that particular server. Now he wants to create AMI whose tags can be defined according to the server, so that he recognize that particular AMI easily. Additionally, \u00a0user can specify the Launch Time of the server with the time on which AMI is being created.<\/p>\n<p>&nbsp;<\/p>\n<p>[js]<br \/>\n_key=Environment<br \/>\n_value=Production<br \/>\necho &quot;Your Specified  Key = $_key and Value = $_value&quot;<br \/>\n[\/js]<\/p>\n<p>User has to specify the Tags of the instances for creating the image<\/p>\n<p>[js]<br \/>\ninstanceIds=($(aws ec2 describe-instances &#8211;query &#8216;Reservations[*].Instances[*].[InstanceId]&#8217; &#8211;filter &quot;Name=instance-state-name,Values=running&quot; &#8211;output text))<br \/>\n[\/js]<\/p>\n<p>Now get the instanceIds of the running instances in an array with this command.<\/p>\n<p>[js]<br \/>\ninstanceKeys=($(aws ec2 describe-instances &#8211;query &#8216;Reservations[*].Instances[*].Tags[*].Key&#8217; &#8211;filter &quot;Name=instance-id,Values=$instanceId&quot; &#8211;output text ))<br \/>\n[\/js]<\/p>\n<p>Put this command in loop of every instanceId to get the Keys of that running instance<\/p>\n<p>[js]<br \/>\nif [ ${instanceKey[$Key_count]}  == $_key ];<br \/>\nthen<br \/>\n    instanceValues=($(aws ec2 describe-instances &#8211;query &#8216;Reservations[*].Instances[*].Tags[*].Value&#8217; &#8211;filter &quot;Name=instance-id,Values=$instanceId&quot; &#8211;output text))<br \/>\n[\/js]<\/p>\n<p>This is command is used in loop for every Key of the instance and it will verify the key specified above<br \/>\nIf it is correct then only it will find the Value otherwise it will be out of the loop.<\/p>\n<p>[js]<br \/>\n\t\t\t\t\tinstanceTime=$(aws ec2 describe-instances &#8211;instance-ids $instanceId  &#8211;query &#8216;Reservations[*].Instances[*].LaunchTime&#8217; &#8211;output text)<br \/>\n\t\t\t\t\t### Command will retrieve the Launch Time of that running instance ###<\/p>\n<p>\t\t\t\t\tTime=$(date -d $instanceTime +%x-%H-%M-%S)<br \/>\n\t\t\t\t\t### Requirement of change in format of time is required ###<br \/>\n\t\t\t\t\t### because in the Name of AMI no &#8216;-&#8216; can be added. It will throw error ###<\/p>\n<p>\t\t\t\t\timageId=($(aws ec2  create-image &#8211;instance-id $instanceId &#8211;name &quot;$instanceName $instanceId $Time&quot; &#8211;output text))<br \/>\n\t\t\t\t\t### AMI will be created ###<br \/>\n\t\t\t\t\t### Id of the created AMI will be stored ###<\/p>\n<p>\t\t\t\t\taws ec2 create-tags &#8211;resources $imageId &#8211;tags Key=Name,Value=&quot;$instanceValues`date`&quot;<br \/>\n\t\t\t\t\t### Tags can be given here to the created AMI with the time when the AMI is been created ###<br \/>\n[\/js]<\/p>\n<p>Use these statements after user specified Key and Value has been verfied with the running instanceIds.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You must be wondering how to make AMI of the Web Server(EC2 instance) in which you have made some changes. In this blog I will walk you through a script that will ease up your work and make AMI of instances with user specified tags. Consider a use-case where user has made some changes to [&hellip;]<\/p>\n","protected":false},"author":261,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3,"footnotes":""},"categories":[1174],"tags":[572,248,1342],"class_list":["post-18601","post","type-post","status-publish","format-standard","hentry","category-aws-2","tag-amazon-ec2","tag-aws","tag-aws-cli"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"You must be wondering how to make AMI of the Web Server(EC2 instance) in which you have made some changes. In this blog I will walk you through a script that will ease up your work and make AMI of instances with user specified tags. Consider a use-case where user has made some changes to\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Aakash Garg\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/tothenewco.pro\/blog\/creating-amis-based-on-tags\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Creating AMIs based on Tags | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"You must be wondering how to make AMI of the Web Server(EC2 instance) in which you have made some changes. In this blog I will walk you through a script that will ease up your work and make AMI of instances with user specified tags. Consider a use-case where user has made some changes to\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/tothenewco.pro\/blog\/creating-amis-based-on-tags\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Creating AMIs based on Tags | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"You must be wondering how to make AMI of the Web Server(EC2 instance) in which you have made some changes. In this blog I will walk you through a script that will ease up your work and make AMI of instances with user specified tags. Consider a use-case where user has made some changes to\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/creating-amis-based-on-tags\\\/#article\",\"name\":\"Creating AMIs based on Tags | TO THE NEW Blog\",\"headline\":\"Creating AMIs based on Tags\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/Aakash\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2015-03-26T19:06:56+05:30\",\"dateModified\":\"2015-06-23T13:57:09+05:30\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/creating-amis-based-on-tags\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/creating-amis-based-on-tags\\\/#webpage\"},\"articleSection\":\"AWS, Amazon EC2, aws, aws cli\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/creating-amis-based-on-tags\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/aws-2\\\/#listItem\",\"name\":\"AWS\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/aws-2\\\/#listItem\",\"position\":2,\"name\":\"AWS\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/aws-2\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/creating-amis-based-on-tags\\\/#listItem\",\"name\":\"Creating AMIs based on Tags\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/creating-amis-based-on-tags\\\/#listItem\",\"position\":3,\"name\":\"Creating AMIs based on Tags\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/aws-2\\\/#listItem\",\"name\":\"AWS\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/Aakash\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/Aakash\\\/\",\"name\":\"Aakash Garg\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/creating-amis-based-on-tags\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a2a15fa1dbed4594e135529cc5bebf8eea3aec738b3e873fee3939e7d8fb0466?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Aakash Garg\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/creating-amis-based-on-tags\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/creating-amis-based-on-tags\\\/\",\"name\":\"Creating AMIs based on Tags | TO THE NEW Blog\",\"description\":\"You must be wondering how to make AMI of the Web Server(EC2 instance) in which you have made some changes. In this blog I will walk you through a script that will ease up your work and make AMI of instances with user specified tags. Consider a use-case where user has made some changes to\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/creating-amis-based-on-tags\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/Aakash\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/Aakash\\\/#author\"},\"datePublished\":\"2015-03-26T19:06:56+05:30\",\"dateModified\":\"2015-06-23T13:57:09+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Creating AMIs based on Tags | TO THE NEW Blog","description":"You must be wondering how to make AMI of the Web Server(EC2 instance) in which you have made some changes. In this blog I will walk you through a script that will ease up your work and make AMI of instances with user specified tags. Consider a use-case where user has made some changes to","canonical_url":"https:\/\/tothenewco.pro\/blog\/creating-amis-based-on-tags\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/tothenewco.pro\/blog\/creating-amis-based-on-tags\/#article","name":"Creating AMIs based on Tags | TO THE NEW Blog","headline":"Creating AMIs based on Tags","author":{"@id":"https:\/\/tothenewco.pro\/blog\/author\/Aakash\/#author"},"publisher":{"@id":"https:\/\/tothenewco.pro\/blog\/#organization"},"datePublished":"2015-03-26T19:06:56+05:30","dateModified":"2015-06-23T13:57:09+05:30","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/tothenewco.pro\/blog\/creating-amis-based-on-tags\/#webpage"},"isPartOf":{"@id":"https:\/\/tothenewco.pro\/blog\/creating-amis-based-on-tags\/#webpage"},"articleSection":"AWS, Amazon EC2, aws, aws cli"},{"@type":"BreadcrumbList","@id":"https:\/\/tothenewco.pro\/blog\/creating-amis-based-on-tags\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog#listItem","position":1,"name":"Home","item":"https:\/\/tothenewco.pro\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog\/category\/aws-2\/#listItem","name":"AWS"}},{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog\/category\/aws-2\/#listItem","position":2,"name":"AWS","item":"https:\/\/tothenewco.pro\/blog\/category\/aws-2\/","nextItem":{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog\/creating-amis-based-on-tags\/#listItem","name":"Creating AMIs based on Tags"},"previousItem":{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog\/creating-amis-based-on-tags\/#listItem","position":3,"name":"Creating AMIs based on Tags","previousItem":{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog\/category\/aws-2\/#listItem","name":"AWS"}}]},{"@type":"Organization","@id":"https:\/\/tothenewco.pro\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/tothenewco.pro\/blog\/"},{"@type":"Person","@id":"https:\/\/tothenewco.pro\/blog\/author\/Aakash\/#author","url":"https:\/\/tothenewco.pro\/blog\/author\/Aakash\/","name":"Aakash Garg","image":{"@type":"ImageObject","@id":"https:\/\/tothenewco.pro\/blog\/creating-amis-based-on-tags\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a2a15fa1dbed4594e135529cc5bebf8eea3aec738b3e873fee3939e7d8fb0466?s=96&d=mm&r=g","width":96,"height":96,"caption":"Aakash Garg"}},{"@type":"WebPage","@id":"https:\/\/tothenewco.pro\/blog\/creating-amis-based-on-tags\/#webpage","url":"https:\/\/tothenewco.pro\/blog\/creating-amis-based-on-tags\/","name":"Creating AMIs based on Tags | TO THE NEW Blog","description":"You must be wondering how to make AMI of the Web Server(EC2 instance) in which you have made some changes. In this blog I will walk you through a script that will ease up your work and make AMI of instances with user specified tags. Consider a use-case where user has made some changes to","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/tothenewco.pro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/tothenewco.pro\/blog\/creating-amis-based-on-tags\/#breadcrumblist"},"author":{"@id":"https:\/\/tothenewco.pro\/blog\/author\/Aakash\/#author"},"creator":{"@id":"https:\/\/tothenewco.pro\/blog\/author\/Aakash\/#author"},"datePublished":"2015-03-26T19:06:56+05:30","dateModified":"2015-06-23T13:57:09+05:30"},{"@type":"WebSite","@id":"https:\/\/tothenewco.pro\/blog\/#website","url":"https:\/\/tothenewco.pro\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/tothenewco.pro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Creating AMIs based on Tags | TO THE NEW Blog","og:description":"You must be wondering how to make AMI of the Web Server(EC2 instance) in which you have made some changes. In this blog I will walk you through a script that will ease up your work and make AMI of instances with user specified tags. Consider a use-case where user has made some changes to","og:url":"https:\/\/tothenewco.pro\/blog\/creating-amis-based-on-tags\/","og:image":"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Creating AMIs based on Tags | TO THE NEW Blog","twitter:description":"You must be wondering how to make AMI of the Web Server(EC2 instance) in which you have made some changes. In this blog I will walk you through a script that will ease up your work and make AMI of instances with user specified tags. Consider a use-case where user has made some changes to","twitter:image":"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"18601","title":"Creating AMIs based on Tags | #site_title","description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-29 16:21:44","updated":"2024-02-29 09:27:24","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/tothenewco.pro\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/tothenewco.pro\/blog\/category\/aws-2\/\" title=\"AWS\">AWS<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tCreating AMIs based on Tags\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/tothenewco.pro\/blog"},{"label":"AWS","link":"https:\/\/tothenewco.pro\/blog\/category\/aws-2\/"},{"label":"Creating AMIs based on Tags","link":"https:\/\/tothenewco.pro\/blog\/creating-amis-based-on-tags\/"}],"_links":{"self":[{"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/posts\/18601","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/users\/261"}],"replies":[{"embeddable":true,"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/comments?post=18601"}],"version-history":[{"count":0,"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/posts\/18601\/revisions"}],"wp:attachment":[{"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/media?parent=18601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/categories?post=18601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/tags?post=18601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}