aws_helper 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +21 -9
- data/lib/awshelper/ec2.rb +6 -6
- data/lib/awshelper/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -19,24 +19,36 @@ Or install it yourself as:
|
|
19
19
|
|
20
20
|
$ gem install aws_helper
|
21
21
|
|
22
|
-
## Usage
|
22
|
+
## Minimal Usage
|
23
23
|
|
24
|
-
|
24
|
+
Assuming server start with an IAM role that have read access to AWS can create and delete snapshots:
|
25
|
+
|
26
|
+
Snapshot EBS root device at /dev/sda1
|
27
|
+
|
28
|
+
aws_helper snap /dev/sda1 --description zzzzzzzzz
|
29
|
+
|
30
|
+
Prune so only keep 7 snapshots:
|
31
|
+
|
32
|
+
aws_helper snap_prune /dev/sda1 --snapshots_to_keep=7
|
33
|
+
|
34
|
+
## Complex Usage
|
35
|
+
|
36
|
+
If your server does not have a role then you need to code the AWS keys which is not best practice:
|
37
|
+
|
38
|
+
Snapshot EBS attached to device /dev/sdf volume vol-123456 access AWS through an http proxy:
|
25
39
|
|
26
40
|
export AWS_ACCESS_KEY_ID ='xxxxxxxxxxxx'
|
27
41
|
export AWS_SECRET_ACCESS_KEY ='yyyyyyyy'
|
28
42
|
export HTTP_PROXY=http://myproxy:port
|
29
|
-
aws_helper snap /dev/sdf --description zzzzzzzzz
|
43
|
+
aws_helper snap /dev/sdf vol-123456 --description zzzzzzzzz
|
30
44
|
|
31
45
|
Prune so only keep 7 snapshots:
|
32
46
|
|
33
47
|
export AWS_ACCESS_KEY_ID ='xxxxxxxxxxxx'
|
34
48
|
export AWS_SECRET_ACCESS_KEY ='yyyyyyyy'
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
Other functions to follow
|
49
|
+
export HTTP_PROXY=http://myproxy:port
|
50
|
+
aws_helper snap_prune /dev/sdf vol-123456 --snapshots_to_keep=7
|
51
|
+
|
52
|
+
Other functions to follow
|
41
53
|
|
42
54
|
|
data/lib/awshelper/ec2.rb
CHANGED
@@ -81,20 +81,20 @@ require 'right_aws'
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def query_role
|
84
|
-
r = open("http://169.254.169.254/latest/meta-data/iam/security-credentials/",options = {:proxy =>
|
84
|
+
r = open("http://169.254.169.254/latest/meta-data/iam/security-credentials/",options = {:proxy => false}).readlines.first
|
85
85
|
r
|
86
86
|
end
|
87
87
|
|
88
88
|
def query_role_credentials(role = query_role)
|
89
89
|
log("Instance has no IAM role.",'err') if role.to_s.empty?
|
90
90
|
fail "Instance has no IAM role." if role.to_s.empty?
|
91
|
-
creds = open("http://169.254.169.254/latest/meta-data/iam/security-credentials/#{role}",options = {:proxy =>
|
91
|
+
creds = open("http://169.254.169.254/latest/meta-data/iam/security-credentials/#{role}",options = {:proxy => false}){|f| JSON.parse(f.string)}
|
92
92
|
log("Retrieved instance credentials for IAM role #{role}")
|
93
93
|
creds
|
94
94
|
end
|
95
95
|
|
96
96
|
def query_instance_id
|
97
|
-
instance_id = open('http://169.254.169.254/latest/meta-data/instance-id',options = {:proxy =>
|
97
|
+
instance_id = open('http://169.254.169.254/latest/meta-data/instance-id',options = {:proxy => false}){|f| f.gets}
|
98
98
|
log("Cannot find instance id!",'err') unless instance_id
|
99
99
|
raise "Cannot find instance id!" unless instance_id
|
100
100
|
log("Instance ID is #{instance_id}")
|
@@ -102,7 +102,7 @@ require 'right_aws'
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def query_ami_id
|
105
|
-
ami_id = open('http://169.254.169.254/latest/meta-data/ami-id',options = {:proxy =>
|
105
|
+
ami_id = open('http://169.254.169.254/latest/meta-data/ami-id',options = {:proxy => false}){|f| f.gets}
|
106
106
|
log("Cannot find ami id!",'err') unless ami_id
|
107
107
|
raise "Cannot find instance id!" unless ami_id
|
108
108
|
log("Aim ID is #{ami_id}")
|
@@ -110,7 +110,7 @@ require 'right_aws'
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def query_local_ipv4
|
113
|
-
local_ipv4 = open('http://169.254.169.254/latest/meta-data/local-ipv4',options = {:proxy =>
|
113
|
+
local_ipv4 = open('http://169.254.169.254/latest/meta-data/local-ipv4',options = {:proxy => false}){|f| f.gets}
|
114
114
|
log("Cannot find local_ipv4!",'err') unless local_ipv4
|
115
115
|
raise "Cannot find local_ipv4!" unless local_ipv4
|
116
116
|
log("local_ipv4 is #{local_ipv4}")
|
@@ -118,7 +118,7 @@ require 'right_aws'
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def query_instance_availability_zone
|
121
|
-
availability_zone = open('http://169.254.169.254/latest/meta-data/placement/availability-zone/', options = {:proxy =>
|
121
|
+
availability_zone = open('http://169.254.169.254/latest/meta-data/placement/availability-zone/', options = {:proxy => false}){|f| f.gets}
|
122
122
|
log("Cannot find availability zone!",'err') unless availability_zone
|
123
123
|
raise "Cannot find availability zone!" unless availability_zone
|
124
124
|
log("Instance's availability zone is #{availability_zone}")
|
data/lib/awshelper/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-11-
|
12
|
+
date: 2014-11-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: right_aws
|