Module: Automan::Mixins::AwsCaller

Included in:
Base
Defined in:
lib/automan/mixins/aws_caller.rb

Constant Summary collapse

S3_PROTO =
's3://'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#asObject



96
97
98
99
100
101
# File 'lib/automan/mixins/aws_caller.rb', line 96

def as
  if @as.nil?
    @as = AWS::AutoScaling.new
  end
  @as
end

#cfnObject



88
89
90
91
92
93
# File 'lib/automan/mixins/aws_caller.rb', line 88

def cfn
  if @cfn.nil?
    @cfn = AWS::CloudFormation.new
  end
  @cfn
end

#ebObject



28
29
30
31
32
33
# File 'lib/automan/mixins/aws_caller.rb', line 28

def eb
  if @eb.nil?
    @eb = AWS::ElasticBeanstalk.new.client
  end
  @eb
end

#ecObject



112
113
114
115
116
117
# File 'lib/automan/mixins/aws_caller.rb', line 112

def ec
  if @ec.nil?
    @ec = AWS::ElastiCache.new
  end
  @ec
end

#ec2Object



120
121
122
123
124
125
# File 'lib/automan/mixins/aws_caller.rb', line 120

def ec2
  if @ec2.nil?
    @ec2 = AWS::EC2.new
  end
  @ec2
end

#elbObject



80
81
82
83
84
85
# File 'lib/automan/mixins/aws_caller.rb', line 80

def elb
  if @elb.nil?
    @elb = AWS::ELB.new
  end
  @elb
end

#r53Object



72
73
74
75
76
77
# File 'lib/automan/mixins/aws_caller.rb', line 72

def r53
  if @r53.nil?
    @r53 = AWS::Route53.new
  end
  @r53
end

#rdsObject



104
105
106
107
108
109
# File 'lib/automan/mixins/aws_caller.rb', line 104

def rds
  if @rds.nil?
    @rds = AWS::RDS.new
  end
  @rds
end

#s3Object



36
37
38
39
40
41
# File 'lib/automan/mixins/aws_caller.rb', line 36

def s3
  if @s3.nil?
    @s3 = AWS::S3.new
  end
  @s3
end

Instance Method Details

#accountObject



7
8
9
# File 'lib/automan/mixins/aws_caller.rb', line 7

def 
  ENV['AWS_ACCOUNT_ID']
end

#configure_aws(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/automan/mixins/aws_caller.rb', line 11

def configure_aws(options={})
  if ENV['AWS_ROLE']
    sts = AWS::STS.new

    @logger.info "Assuming role #{ENV['AWS_ROLE']}"
    provider = AWS::Core::CredentialProviders::AssumeRoleProvider.new(
      sts: sts,
      role_arn: ENV['AWS_ROLE'],
      role_session_name: "automan-aws-sdk"
    )
    options[:credential_provider] = provider
  end

  AWS.config(options)
end

#looks_like_s3_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/automan/mixins/aws_caller.rb', line 45

def looks_like_s3_path?(path)
  path.start_with? S3_PROTO
end

#parse_s3_path(path) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/automan/mixins/aws_caller.rb', line 49

def parse_s3_path(path)
  if !looks_like_s3_path? path
    raise ArgumentError, "s3 path must start with '#{S3_PROTO}'"
  end

  rel_path = path[S3_PROTO.length..-1]
  bucket = rel_path.split('/').first
  key = rel_path.split('/')[1..-1].join('/')

  return bucket, key
end

#s3_object_exists?(s3_path) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
# File 'lib/automan/mixins/aws_caller.rb', line 61

def s3_object_exists?(s3_path)
  bucket, key = parse_s3_path s3_path
  s3.buckets[bucket].objects[key].exists?
end

#s3_read(s3_path) ⇒ Object



66
67
68
69
# File 'lib/automan/mixins/aws_caller.rb', line 66

def s3_read(s3_path)
  bucket, key = parse_s3_path s3_path
  s3.buckets[bucket].objects[key].read
end