Skip to content

Commit e99aa6f

Browse files
author
Alena Kastsiukavets
committed
Update install\update script to use information about region from instance metadata
# Why is this change needed? Titan zone has a different format of AZ-region # How does it address the issue? Extract information about region from region metadata # How was this tested ? ``` sudo ./install auto ``` OUTPUT: ``` INFO -- : Starting Ruby version check. INFO -- : Starting update check. INFO -- : Attempting to automatically detect supported package manager type for INFO -- : Checking AWS_REGION environment variable for region information... INFO -- : Checking EC2 metadata service for region information... INFO -- : Downloading version file from bucket aws-codedeploy-eu-west-1 and key INFO -- : Downloading version file from bucket aws-codedeploy-eu-west-1 and key INFO -- : Downloading package from bucket aws-codedeploy-eu-west-1 and key releases/codedeploy-agent-1.0-1.1597.noarch.rpm... ``` ``` unset AWS_REGION sudo ./update auto ``` OUTPUT: ``` INFO -- : Starting Ruby version check. INFO -- : Starting update check. INFO -- : Attempting to automatically detect supported package manager type for INFO -- : Checking AWS_REGION environment variable for region information... INFO -- : Checking EC2 metadata service for region information... INFO -- : Downloading version file from BUCKET aws-codedeploy-eu-west-1 and key latest/VERSION... ``` cr https://code.amazon.com/reviews/CR-22605355
1 parent aaadc81 commit e99aa6f

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

bin/install

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# than 2.0. Testing on multiple Ruby versions is required for
66
# changes to this part of the code.
77
##################################################################
8+
require 'json'
89

910
class Proxy
1011
instance_methods.each do |m|
@@ -198,20 +199,14 @@ EOF
198199

199200
def get_ec2_metadata_region
200201
begin
201-
uri = URI.parse('http://169.254.169.254/latest/meta-data/placement/availability-zone')
202-
az = uri.read(:read_timeout => 120)
203-
az.strip
202+
uri = URI.parse('http://169.254.169.254/latest/dynamic/instance-identity/document')
203+
document_string = uri.read(:read_timeout => 120)
204+
doc = JSON.parse(document_string.strip)
205+
return doc['region'].strip
204206
rescue
205207
@log.warn("Could not get region from EC2 metadata service at '#{uri.to_s}'")
206208
return nil
207209
end
208-
209-
if (az !~ /[a-z]{2}-[a-z]+-\d+[a-z]/)
210-
@log.warn("Invalid availability zone name: '#{az}'.")
211-
return nil
212-
else
213-
return az.chop
214-
end
215210
end
216211

217212
def get_region

bin/update

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# than 2.0. Testing on multiple Ruby versions is required for
66
# changes to this part of the code.
77
##################################################################
8+
require 'json'
89

910
class Proxy
1011
instance_methods.each do |m|
@@ -270,20 +271,14 @@ EOF
270271

271272
def get_ec2_metadata_region
272273
begin
273-
uri = URI.parse('http://169.254.169.254/latest/meta-data/placement/availability-zone')
274-
az = uri.read(:read_timeout => 120)
275-
az.strip
274+
uri = URI.parse('http://169.254.169.254/latest/dynamic/instance-identity/document')
275+
document_string = uri.read(:read_timeout => 120)
276+
doc = JSON.parse(document_string.strip)
277+
return doc['region'].strip
276278
rescue
277279
@log.warn("Could not get region from EC2 metadata service at '#{uri.to_s}'")
278280
return nil
279281
end
280-
281-
if (az !~ /[a-z]{2}-[a-z]+-\d+[a-z]/)
282-
@log.warn("Invalid availability zone name: '#{az}'.")
283-
return nil
284-
else
285-
return az.chop
286-
end
287282
end
288283

289284
def get_region

0 commit comments

Comments
 (0)