aws-ec2 1.4.2 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d442b6604282a2348109a44d78ff9f1e9ecc2bcf73761575f9bb5da1d522eefe
4
- data.tar.gz: 64028e1f0a9689427ca076707e9dd9cd601be9f31df695ac22e846a7d1447187
3
+ metadata.gz: 133b3adbf26d2f3f9e02e7aa2f97dfc3e899cff09e3c7195dd2fb3670c35f1d2
4
+ data.tar.gz: d16e6f935714439ae350822441e84f7192ba14837d2c88df42517d77e49e2e77
5
5
  SHA512:
6
- metadata.gz: bbffaf1544f51801165d44adcb40b0c5bfb95db733cdadb062d9dc947861be2fdaa373d1440c29ea675e4020c8449d1ab2f9ff3b04761d0f95df9f198f1e5aa9
7
- data.tar.gz: c7f919272fd4c804d7659499c8480914068dc005975ec469bc7412a170e9d90b8f60c6aa331490c7b3653d52c4864bc24f1af3ed1d45c050711de4abd04270d7
6
+ metadata.gz: 7cce36e27bb90ac8e05c1f29ac209e6d6804510d0074da10cde099972f90f67af2cf6660a276b9f405f71284f1e16d1f5d1e4880ff0ce7cb5e9cbe53b99986b9
7
+ data.tar.gz: c1331df63412bfc9ecf623912257c3a25615e3e631edccc30f2a22daf5c925f18175b5dc4a0246a0e93a924d296e5fd5ef3d99242f1a950f8b224245f4dd8d92
@@ -3,6 +3,9 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [1.4.3]
7
+ - fix get_region when aws-ec2 called from an ec2 instance
8
+
6
9
  ## [1.4.2]
7
10
  - fix cloudwatch for ubuntu
8
11
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aws-ec2 (1.3.1)
4
+ aws-ec2 (1.4.2)
5
5
  activesupport
6
6
  aws-sdk-ec2
7
7
  aws-sdk-s3
@@ -29,26 +29,6 @@ module AwsEc2
29
29
  display_cloudwatch_info(instance_id)
30
30
  end
31
31
 
32
- def display_cloudwatch_info(instance_id)
33
- return unless @options[:cloudwatch]
34
-
35
- region = `aws configure get region`.strip
36
- region = 'us-east-1' if region == ''
37
- url = "https://#{region}.console.aws.amazon.com/cloudwatch/home?region=#{region}#logEventViewer:group=ec2;stream=#{instance_id}/var/log/cloud-init-output.log"
38
- puts "To view instance's cloudwatch logs visit:"
39
- puts " #{url}"
40
- puts "Note: It takes a little time for the instance to launch and report logs."
41
- add_to_clipboard(url)
42
- end
43
-
44
- def add_to_clipboard(text)
45
- return unless RUBY_PLATFORM =~ /darwin/
46
- return unless system("type pbcopy > /dev/null")
47
-
48
- system(%[echo "#{text}" | pbcopy])
49
- puts "Pro tip: The CloudWatch Console Link has been added to your copy-and-paste clipboard."
50
- end
51
-
52
32
  def run_instances(params)
53
33
  ec2.run_instances(params)
54
34
  rescue Aws::EC2::Errors::ServiceError => e
@@ -107,6 +87,43 @@ module AwsEc2
107
87
  exit
108
88
  end
109
89
 
90
+ def display_cloudwatch_info(instance_id)
91
+ return unless @options[:cloudwatch]
92
+
93
+ region = get_region
94
+ url = "https://#{region}.console.aws.amazon.com/cloudwatch/home?region=#{region}#logEventViewer:group=ec2;stream=#{instance_id}/var/log/cloud-init-output.log"
95
+ puts "To view instance's cloudwatch logs visit:"
96
+ puts " #{url}"
97
+ puts "Note: It takes a little time for the instance to launch and report logs."
98
+ add_to_clipboard(url)
99
+ end
100
+
101
+ def add_to_clipboard(text)
102
+ return unless RUBY_PLATFORM =~ /darwin/
103
+ return unless system("type pbcopy > /dev/null")
104
+
105
+ system(%[echo "#{text}" | pbcopy])
106
+ puts "Pro tip: The CloudWatch Console Link has been added to your copy-and-paste clipboard."
107
+ end
108
+
109
+ def get_region
110
+ # Highest precedence is the setting in ~/.aws/config and AWS_PROFILE used
111
+ aws_found = system("type aws > /dev/null")
112
+ if aws_found
113
+ region = `aws configure get region`.strip
114
+ return region
115
+ end
116
+
117
+ # Assumes instace being launched in the same region as the calling ec2 instance
118
+ curl_found = system("type curl > /dev/null")
119
+ if curl_found
120
+ region = `curl --connect-timeout 3 -s 169.254.169.254/latest/meta-data/placement/availability-zone | sed s'/.$//'`
121
+ return region unless region == ''
122
+ end
123
+
124
+ return 'us-east-1' # fallback default
125
+ end
126
+
110
127
  def pretty_display(data)
111
128
  data = data.deep_stringify_keys
112
129
 
@@ -79,6 +79,6 @@ datetime_format =
79
79
  EOF
80
80
 
81
81
  if [ -f /etc/awslogs/awscli.conf ]; then
82
- region=$(curl 169.254.169.254/latest/meta-data/placement/availability-zone | sed s'/.$//')
82
+ region=$(curl -s 169.254.169.254/latest/meta-data/placement/availability-zone | sed s'/.$//')
83
83
  sed -i -e "s/region = us-east-1/region = $region/g" /etc/awslogs/awscli.conf
84
84
  fi
@@ -1,3 +1,3 @@
1
1
  module AwsEc2
2
- VERSION = "1.4.2"
2
+ VERSION = "1.4.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-ec2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen