{"id":8347,"date":"2013-02-04T22:54:37","date_gmt":"2013-02-04T22:54:37","guid":{"rendered":"https:\/\/gosqeng.test\/?p=186"},"modified":"2019-11-28T12:35:07","modified_gmt":"2019-11-28T12:35:07","slug":"how-we-use-ec2-instance-tags","status":"publish","type":"post","link":"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags","title":{"rendered":"How we use EC2 Instance tags"},"content":{"rendered":"<p>Amazon EC2 conveniently offers the ability to associate (currently) up to 10 key-value &#8220;tags&#8221; to EC2 resources like instances and EBS volumes, containing any information you like. This is particularly useful for custom server nomenclature, data assignment, grouping, identification and so on, to help you organise and work with your instances conveniently.<\/p>\n<h3>Naming<\/h3>\n<p>The most commonly used instance tag is one with the key &#8220;Name&#8221;. AWS seems to encourage the use of this themselves with widespread support for displaying the Name tag in the Management Console. Wherever possible\/implemented, the console will show you the Name tag instead of just the instance ID, saving you the trouble of looking up the nondescript instance ID to ensure you&#8217;re working with the right server.<\/p>\n<p>Here&#8217;s an example of what the Name tag looks like for one of the many instances busily working away on the analytics you love:<\/p>\n<pre><code>nginx-1\n  ^   ^\n  |   |\nname  ID\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>The two-part tag contains a name and a unique ID, delimited by a single hyphen. The name portion indicates what cluster, or &#8220;role&#8221;, the instance is assigned. The ID portion is a numerical ID to uniquely identify that instance.<\/p>\n<p>When you have a large number of instances to manage, identifying instances in this way is an essential part of the ops process. The real magic happens when you start using the EC2 API to query and minipulate instances based on their tags. It helps us classify instances, perform cluster-wide operations on related instances, deploy services to a target portion of instances, along with many other benefits.<\/p>\n<h3>Hostnames<\/h3>\n<p>Now that all our instances have name tags, we can make use of these tags for server identification in a way that&#8217;s useful for our applications and services. We&#8217;ve built a tool in Ruby that makes use of the <a href=\"http:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/APIReference\/\">AWS API<\/a> to load a list of instances, their internal IP addresses and their Name tags. Using <a href=\"https:\/\/github.com\/bjeanes\/ghost\">Ghost<\/a>, it then writes this information to the \/etc\/hosts file as host records, like this:<\/p>\n<pre><code>127.0.0.1 localhost\n\n# ghost\nnginx-1 10.100.83.239\nnodejs-1 10.100.30.24\nnodejs-2 10.100.16.87\n# end ghost\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>This service continually runs via <a href=\"http:\/\/upstart.ubuntu.com\/\">upstart<\/a> on every instance, so that they each have up-to-date internal IP addresses mapped to a readable hostname for every other instance we own. As a result, there&#8217;s always a predictable<a href=\"#uptime-note\">*<\/a>, standardised way for instances and services to communicate with each other via readable, identifiable hostnames.<\/p>\n<p>This is great because it means you don&#8217;t need as much isolated logic to resolve and connect IP addresses in your applications. It also makes configuring distributed services, such as monitoring, logging, and load balancing tools less of a headache. This is because hostnames for these programs tend to be hard-coded in config files, and this way they&#8217;ll change less often.<\/p>\n<p><b id=\"uptime-note\">Notes<\/b><\/p>\n<ul>\n<li>It&#8217;s not completely unknown for the EC2 API to encounter problems which means your app will be unable to load instance tags and assign hostnames. It goes without saying in the cloud anyway, but you need to be able to gracefully handle this scenario in case of a service outage.<\/li>\n<li>Make sure you&#8217;ve authorised your instances to access each other through their <a href=\"http:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/using-network-security.html\">EC2 Security Groups<\/a>. You need only open ports to other security groups in your account.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Amazon EC2 conveniently offers the ability to associate (currently) up to 10 key-value &#8220;tags&#8221; to EC2 resources like instances and&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1452],"tags":[93,303,1180,492],"class_list":["post-8347","post","type-post","status-publish","format-standard","hentry","category-engineering","tag-amazon","tag-ec2","tag-internal","tag-ip"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v18.6 (Yoast SEO v19.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How we use EC2 Instance tags - GoSquared Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How we use EC2 Instance tags\" \/>\n<meta property=\"og:description\" content=\"Amazon EC2 conveniently offers the ability to associate (currently) up to 10 key-value &#8220;tags&#8221; to EC2 resources like instances and...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags\" \/>\n<meta property=\"og:site_name\" content=\"GoSquared Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GoSquared\" \/>\n<meta property=\"article:published_time\" content=\"2013-02-04T22:54:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-11-28T12:35:07+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@TheDeveloper\" \/>\n<meta name=\"twitter:site\" content=\"@GoSquared\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Geoff Wagstaff\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/#organization\",\"name\":\"GoSquared\",\"url\":\"https:\/\/www.gosquared.com\/blog\/\",\"sameAs\":[\"https:\/\/instagram.com\/gosquaredteam\",\"https:\/\/www.linkedin.com\/company\/go-squared-ltd.\",\"https:\/\/www.facebook.com\/GoSquared\",\"https:\/\/twitter.com\/GoSquared\"],\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.gosquared.com\/blog\/wp-content\/uploads\/2015\/07\/gosquared.png\",\"contentUrl\":\"https:\/\/www.gosquared.com\/blog\/wp-content\/uploads\/2015\/07\/gosquared.png\",\"width\":1270,\"height\":250,\"caption\":\"GoSquared\"},\"image\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/#website\",\"url\":\"https:\/\/www.gosquared.com\/blog\/\",\"name\":\"GoSquared Blog\",\"description\":\"Turn visitors into customers.\",\"publisher\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.gosquared.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags#webpage\",\"url\":\"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags\",\"name\":\"How we use EC2 Instance tags - GoSquared Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/#website\"},\"datePublished\":\"2013-02-04T22:54:37+00:00\",\"dateModified\":\"2019-11-28T12:35:07+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.gosquared.com\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How we use EC2 Instance tags\"}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags#webpage\"},\"author\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/56a3341790c8a0603f96066fb8d42448\"},\"headline\":\"How we use EC2 Instance tags\",\"datePublished\":\"2013-02-04T22:54:37+00:00\",\"dateModified\":\"2019-11-28T12:35:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags#webpage\"},\"wordCount\":522,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.gosquared.com\/blog\/#organization\"},\"keywords\":[\"Amazon\",\"EC2\",\"Internal\",\"IP\"],\"articleSection\":[\"Engineering\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags#respond\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/56a3341790c8a0603f96066fb8d42448\",\"name\":\"Geoff Wagstaff\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/66792d2e4d04406697b9a5f322664691590a386bc15b7146d143bbca07aa8889?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/66792d2e4d04406697b9a5f322664691590a386bc15b7146d143bbca07aa8889?s=96&d=mm&r=g\",\"caption\":\"Geoff Wagstaff\"},\"sameAs\":[\"https:\/\/twitter.com\/TheDeveloper\"],\"url\":\"https:\/\/www.gosquared.com\/blog\/author\/echo\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How we use EC2 Instance tags - GoSquared Blog","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:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags","og_locale":"en_US","og_type":"article","og_title":"How we use EC2 Instance tags","og_description":"Amazon EC2 conveniently offers the ability to associate (currently) up to 10 key-value &#8220;tags&#8221; to EC2 resources like instances and...","og_url":"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags","og_site_name":"GoSquared Blog","article_publisher":"https:\/\/www.facebook.com\/GoSquared","article_published_time":"2013-02-04T22:54:37+00:00","article_modified_time":"2019-11-28T12:35:07+00:00","twitter_card":"summary_large_image","twitter_creator":"@TheDeveloper","twitter_site":"@GoSquared","twitter_misc":{"Written by":"Geoff Wagstaff","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Organization","@id":"https:\/\/www.gosquared.com\/blog\/#organization","name":"GoSquared","url":"https:\/\/www.gosquared.com\/blog\/","sameAs":["https:\/\/instagram.com\/gosquaredteam","https:\/\/www.linkedin.com\/company\/go-squared-ltd.","https:\/\/www.facebook.com\/GoSquared","https:\/\/twitter.com\/GoSquared"],"logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.gosquared.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.gosquared.com\/blog\/wp-content\/uploads\/2015\/07\/gosquared.png","contentUrl":"https:\/\/www.gosquared.com\/blog\/wp-content\/uploads\/2015\/07\/gosquared.png","width":1270,"height":250,"caption":"GoSquared"},"image":{"@id":"https:\/\/www.gosquared.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"WebSite","@id":"https:\/\/www.gosquared.com\/blog\/#website","url":"https:\/\/www.gosquared.com\/blog\/","name":"GoSquared Blog","description":"Turn visitors into customers.","publisher":{"@id":"https:\/\/www.gosquared.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.gosquared.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags#webpage","url":"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags","name":"How we use EC2 Instance tags - GoSquared Blog","isPartOf":{"@id":"https:\/\/www.gosquared.com\/blog\/#website"},"datePublished":"2013-02-04T22:54:37+00:00","dateModified":"2019-11-28T12:35:07+00:00","breadcrumb":{"@id":"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.gosquared.com\/blog"},{"@type":"ListItem","position":2,"name":"How we use EC2 Instance tags"}]},{"@type":"Article","@id":"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags#article","isPartOf":{"@id":"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags#webpage"},"author":{"@id":"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/56a3341790c8a0603f96066fb8d42448"},"headline":"How we use EC2 Instance tags","datePublished":"2013-02-04T22:54:37+00:00","dateModified":"2019-11-28T12:35:07+00:00","mainEntityOfPage":{"@id":"https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags#webpage"},"wordCount":522,"commentCount":0,"publisher":{"@id":"https:\/\/www.gosquared.com\/blog\/#organization"},"keywords":["Amazon","EC2","Internal","IP"],"articleSection":["Engineering"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.gosquared.com\/blog\/how-we-use-ec2-instance-tags#respond"]}]},{"@type":"Person","@id":"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/56a3341790c8a0603f96066fb8d42448","name":"Geoff Wagstaff","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.gosquared.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/66792d2e4d04406697b9a5f322664691590a386bc15b7146d143bbca07aa8889?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/66792d2e4d04406697b9a5f322664691590a386bc15b7146d143bbca07aa8889?s=96&d=mm&r=g","caption":"Geoff Wagstaff"},"sameAs":["https:\/\/twitter.com\/TheDeveloper"],"url":"https:\/\/www.gosquared.com\/blog\/author\/echo"}]}},"wps_subtitle":"Using instance tags to simplify EC2 management","_links":{"self":[{"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/posts\/8347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/comments?post=8347"}],"version-history":[{"count":0,"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/posts\/8347\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/media?parent=8347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/categories?post=8347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gosquared.com\/blog\/wp-json\/wp\/v2\/tags?post=8347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}