{"action":"created","comment":{"url":"https://api.github.com/repos/intercom/elasticsearch-ssm/pulls/comments/257294352","pull_request_review_id":204315420,"id":257294352,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI1NzI5NDM1Mg==","diff_hunk":"@@ -0,0 +1,71 @@\n+# frozen_string_literal: true\n+\n+require 'json'\n+require 'typhoeus'\n+require 'aws-sdk'\n+\n+module ElasticsearchSSM\n+  #\n+  # Slim wrapper for common AWS operations\n+  #\n+  class AwsClient\n+    LOCAL_AWS_REGION = 'us-east-1'\n+    AWS_LOCAL_ID_URL = '169.254.169.254/latest/meta-data/instance-id'\n+\n+    attr_reader :elb_client, :opsworks_client, :opsworks_agent, :instance_id, :elb_name\n+\n+    def initialize\n+      @elb_client = Aws::ElasticLoadBalancing::Client.new(region: LOCAL_AWS_REGION, credentials: Aws::InstanceProfileCredentials.new)\n+      @opsworks_client = Aws::OpsWorks::Client.new(region: LOCAL_AWS_REGION, credentials: Aws::InstanceProfileCredentials.new)\n+      @opsworks_agent = OpsWorksAgent.new\n+      @instance_id = local_instance_id\n+      @elb_name = local_elb_name\n+    end\n+\n+    def detach_from_elb\n+      raise 'Connection draining is not enabled on the cluster.' unless connection_draining_settings.enabled\n+\n+      elb_client.deregister_instances_from_load_balancer(\n+        instances: [\n+          {\n+            instance_id: instance_id\n+          }\n+        ],\n+        load_balancer_name: elb_name\n+      )\n+\n+      sleep(connection_draining_settings.timeout)\n+    end\n+\n+    def attach_to_elb\n+      elb_client.register_instances_with_load_balancer(","path":"lib/aws_client.rb","position":41,"original_position":41,"commit_id":"a9c1c50fa96689e9bd415f2fc3a77eae718126f9","original_commit_id":"a9c1c50fa96689e9bd415f2fc3a77eae718126f9","user":{"login":"andrejbl","id":36857192,"node_id":"MDQ6VXNlcjM2ODU3MTky","avatar_url":"https://avatars1.githubusercontent.com/u/36857192?v=4","gravatar_id":"","url":"https://api.github.com/users/andrejbl","html_url":"https://github.com/andrejbl","followers_url":"https://api.github.com/users/andrejbl/followers","following_url":"https://api.github.com/users/andrejbl/following{/other_user}","gists_url":"https://api.github.com/users/andrejbl/gists{/gist_id}","starred_url":"https://api.github.com/users/andrejbl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrejbl/subscriptions","organizations_url":"https://api.github.com/users/andrejbl/orgs","repos_url":"https://api.github.com/users/andrejbl/repos","events_url":"https://api.github.com/users/andrejbl/events{/privacy}","received_events_url":"https://api.github.com/users/andrejbl/received_events","type":"User","site_admin":false},"body":"no, attaching is idempotent","created_at":"2019-02-15T16:07:40Z","updated_at":"2019-02-15T16:07:40Z","html_url":"https://github.com/intercom/elasticsearch-ssm/pull/15#discussion_r257294352","pull_request_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/pulls/15","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/intercom/elasticsearch-ssm/pulls/comments/257294352"},"html":{"href":"https://github.com/intercom/elasticsearch-ssm/pull/15#discussion_r257294352"},"pull_request":{"href":"https://api.github.com/repos/intercom/elasticsearch-ssm/pulls/15"}},"in_reply_to_id":257294014},"pull_request":{"url":"https://api.github.com/repos/intercom/elasticsearch-ssm/pulls/15","id":253476917,"node_id":"MDExOlB1bGxSZXF1ZXN0MjUzNDc2OTE3","html_url":"https://github.com/intercom/elasticsearch-ssm/pull/15","diff_url":"https://github.com/intercom/elasticsearch-ssm/pull/15.diff","patch_url":"https://github.com/intercom/elasticsearch-ssm/pull/15.patch","issue_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/issues/15","number":15,"state":"open","locked":false,"title":"Adding ELB removal logic to SSM security patching","user":{"login":"andrejbl","id":36857192,"node_id":"MDQ6VXNlcjM2ODU3MTky","avatar_url":"https://avatars1.githubusercontent.com/u/36857192?v=4","gravatar_id":"","url":"https://api.github.com/users/andrejbl","html_url":"https://github.com/andrejbl","followers_url":"https://api.github.com/users/andrejbl/followers","following_url":"https://api.github.com/users/andrejbl/following{/other_user}","gists_url":"https://api.github.com/users/andrejbl/gists{/gist_id}","starred_url":"https://api.github.com/users/andrejbl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrejbl/subscriptions","organizations_url":"https://api.github.com/users/andrejbl/orgs","repos_url":"https://api.github.com/users/andrejbl/repos","events_url":"https://api.github.com/users/andrejbl/events{/privacy}","received_events_url":"https://api.github.com/users/andrejbl/received_events","type":"User","site_admin":false},"body":"High traffic ES clusters such as UserSearch will suffer broken client connections with the standard SSM patching logic of stopping nodes. A safer alternative is to: enable connection draining on ES ELBs and remove the node from ELB before shut down and add it to ELB after the restart.\r\n\r\nThis PR covers the SSM ruby script changes for the latter. Former will be enabled on the clusters through a separate change.","created_at":"2019-02-15T15:57:00Z","updated_at":"2019-02-15T16:07:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c6169abbd973d86a0f5c074a146b6da5d1aa8b26","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/pulls/15/commits","review_comments_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/pulls/15/comments","review_comment_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/issues/15/comments","statuses_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/statuses/a9c1c50fa96689e9bd415f2fc3a77eae718126f9","head":{"label":"intercom:ab/remove-client-nodes-from-elb","ref":"ab/remove-client-nodes-from-elb","sha":"a9c1c50fa96689e9bd415f2fc3a77eae718126f9","user":{"login":"intercom","id":6585,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY1ODU=","avatar_url":"https://avatars0.githubusercontent.com/u/6585?v=4","gravatar_id":"","url":"https://api.github.com/users/intercom","html_url":"https://github.com/intercom","followers_url":"https://api.github.com/users/intercom/followers","following_url":"https://api.github.com/users/intercom/following{/other_user}","gists_url":"https://api.github.com/users/intercom/gists{/gist_id}","starred_url":"https://api.github.com/users/intercom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/intercom/subscriptions","organizations_url":"https://api.github.com/users/intercom/orgs","repos_url":"https://api.github.com/users/intercom/repos","events_url":"https://api.github.com/users/intercom/events{/privacy}","received_events_url":"https://api.github.com/users/intercom/received_events","type":"Organization","site_admin":false},"repo":{"id":167949322,"node_id":"MDEwOlJlcG9zaXRvcnkxNjc5NDkzMjI=","name":"elasticsearch-ssm","full_name":"intercom/elasticsearch-ssm","private":false,"owner":{"login":"intercom","id":6585,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY1ODU=","avatar_url":"https://avatars0.githubusercontent.com/u/6585?v=4","gravatar_id":"","url":"https://api.github.com/users/intercom","html_url":"https://github.com/intercom","followers_url":"https://api.github.com/users/intercom/followers","following_url":"https://api.github.com/users/intercom/following{/other_user}","gists_url":"https://api.github.com/users/intercom/gists{/gist_id}","starred_url":"https://api.github.com/users/intercom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/intercom/subscriptions","organizations_url":"https://api.github.com/users/intercom/orgs","repos_url":"https://api.github.com/users/intercom/repos","events_url":"https://api.github.com/users/intercom/events{/privacy}","received_events_url":"https://api.github.com/users/intercom/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/intercom/elasticsearch-ssm","description":"Repo for all of Intercom's Elasticsearch automation managed through AWS Systems Manager","fork":false,"url":"https://api.github.com/repos/intercom/elasticsearch-ssm","forks_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/forks","keys_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/teams","hooks_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/hooks","issue_events_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/issues/events{/number}","events_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/events","assignees_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/assignees{/user}","branches_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/branches{/branch}","tags_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/tags","blobs_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/git/refs{/sha}","trees_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/statuses/{sha}","languages_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/languages","stargazers_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/stargazers","contributors_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/contributors","subscribers_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/subscribers","subscription_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/subscription","commits_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/commits{/sha}","git_commits_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/git/commits{/sha}","comments_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/comments{/number}","issue_comment_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/issues/comments{/number}","contents_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/contents/{+path}","compare_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/merges","archive_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/downloads","issues_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/issues{/number}","pulls_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/pulls{/number}","milestones_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/milestones{/number}","notifications_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/labels{/name}","releases_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/releases{/id}","deployments_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/deployments","created_at":"2019-01-28T11:14:23Z","updated_at":"2019-02-12T17:51:13Z","pushed_at":"2019-02-15T15:57:00Z","git_url":"git://github.com/intercom/elasticsearch-ssm.git","ssh_url":"git@github.com:intercom/elasticsearch-ssm.git","clone_url":"https://github.com/intercom/elasticsearch-ssm.git","svn_url":"https://github.com/intercom/elasticsearch-ssm","homepage":null,"size":28,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"intercom:master","ref":"master","sha":"7a5b5412c4176156cc505b8c77a65eaf6990b950","user":{"login":"intercom","id":6585,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY1ODU=","avatar_url":"https://avatars0.githubusercontent.com/u/6585?v=4","gravatar_id":"","url":"https://api.github.com/users/intercom","html_url":"https://github.com/intercom","followers_url":"https://api.github.com/users/intercom/followers","following_url":"https://api.github.com/users/intercom/following{/other_user}","gists_url":"https://api.github.com/users/intercom/gists{/gist_id}","starred_url":"https://api.github.com/users/intercom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/intercom/subscriptions","organizations_url":"https://api.github.com/users/intercom/orgs","repos_url":"https://api.github.com/users/intercom/repos","events_url":"https://api.github.com/users/intercom/events{/privacy}","received_events_url":"https://api.github.com/users/intercom/received_events","type":"Organization","site_admin":false},"repo":{"id":167949322,"node_id":"MDEwOlJlcG9zaXRvcnkxNjc5NDkzMjI=","name":"elasticsearch-ssm","full_name":"intercom/elasticsearch-ssm","private":false,"owner":{"login":"intercom","id":6585,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY1ODU=","avatar_url":"https://avatars0.githubusercontent.com/u/6585?v=4","gravatar_id":"","url":"https://api.github.com/users/intercom","html_url":"https://github.com/intercom","followers_url":"https://api.github.com/users/intercom/followers","following_url":"https://api.github.com/users/intercom/following{/other_user}","gists_url":"https://api.github.com/users/intercom/gists{/gist_id}","starred_url":"https://api.github.com/users/intercom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/intercom/subscriptions","organizations_url":"https://api.github.com/users/intercom/orgs","repos_url":"https://api.github.com/users/intercom/repos","events_url":"https://api.github.com/users/intercom/events{/privacy}","received_events_url":"https://api.github.com/users/intercom/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/intercom/elasticsearch-ssm","description":"Repo for all of Intercom's Elasticsearch automation managed through AWS Systems Manager","fork":false,"url":"https://api.github.com/repos/intercom/elasticsearch-ssm","forks_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/forks","keys_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/teams","hooks_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/hooks","issue_events_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/issues/events{/number}","events_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/events","assignees_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/assignees{/user}","branches_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/branches{/branch}","tags_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/tags","blobs_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/git/refs{/sha}","trees_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/statuses/{sha}","languages_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/languages","stargazers_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/stargazers","contributors_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/contributors","subscribers_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/subscribers","subscription_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/subscription","commits_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/commits{/sha}","git_commits_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/git/commits{/sha}","comments_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/comments{/number}","issue_comment_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/issues/comments{/number}","contents_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/contents/{+path}","compare_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/merges","archive_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/downloads","issues_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/issues{/number}","pulls_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/pulls{/number}","milestones_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/milestones{/number}","notifications_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/labels{/name}","releases_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/releases{/id}","deployments_url":"https://api.github.com/repos/intercom/elasticsearch-ssm/deployments","created_at":"2019-01-28T11:14:23Z","updated_at":"2019-02-12T17:51:13Z","pushed_at":"2019-02-15T15:57:00Z","git_url":"git://github.com/intercom/elasticsearch-ssm.git","ssh_url":"git@github.com:intercom/elasticsearch-ssm.git","clone_url":"https://github.com/intercom/elasticsearch-ssm.git","svn_url":"https://github.com/intercom/elasticsearch-ssm","homepage":null,"size":28,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/intercom/elasticsearch-ssm/pulls/15"},"html":{"href":"https://github.com/intercom/elasticsearch-ssm/pull/15"},"issue":{"href":"https://api.github.com/repos/intercom/elasticsearch-ssm/issues/15"},"comments":{"href":"https://api.github.com/repos/intercom/elasticsearch-ssm/issues/15/comments"},"review_comments":{"href":"https://api.github.com/repos/intercom/elasticsearch-ssm/pulls/15/comments"},"review_comment":{"href":"https://api.github.com/repos/intercom/elasticsearch-ssm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/intercom/elasticsearch-ssm/pulls/15/commits"},"statuses":{"href":"https://api.github.com/repos/intercom/elasticsearch-ssm/statuses/a9c1c50fa96689e9bd415f2fc3a77eae718126f9"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"andrejbl"}}