-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaws.rb
52 lines (45 loc) · 1.1 KB
/
aws.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'aws-sdk'
class AwsUtil
def initialize(access_key, secret_key, region)
Aws.config.update({
region: region,
credentials: Aws::Credentials.new(access_key, secret_key),
})
@ec2_client = Aws::EC2::Client.new
end
def get_all_running_instances
# Get informations about instances
begin
ec2_resp = @ec2_client.describe_instances({
filters: [
{
name: "instance-state-name",
values: ["running"],
},
],
max_results: 1000
})
rescue Aws::EC2::Errors::ServiceError => error
puts "failed when calling aws ec2 api: #{error.message}"
abort
end
ec2_resp
end
def get_all_attached_volumes_by_ids(ids)
begin
ec2_vol_resp = @ec2_client.describe_volumes({
volume_ids: ids,
filters: [
{
name: "attachment.status",
values: ["attached"],
},
]
})
rescue Aws::EC2::Errors::ServiceError => error
puts "failed when calling aws ec2 api: #{error.message}"
abort
end
ec2_vol_resp
end
end