Class: RubyAemAws::AemAws

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_aem_aws.rb

Overview

AemAws class represents the AWS stack for AEM.

Instance Method Summary collapse

Constructor Details

#initialize(conf = {}) ⇒ Object

  • aws_region: the AWS region (eg ap-southeast-2)

  • aws_access_key_id: the AWS access key

  • aws_secret_access_key: the AWS secret access key

  • aws_session_token: session token from STS

  • aws_profile: AWS profile name

Parameters:

  • conf (defaults to: {})

    configuration hash of the following configuration values:

Raises:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ruby_aem_aws.rb', line 38

def initialize(conf = {})
  conf[:aws_region] ||= Constants::REGION_DEFAULT
  conf[:aws_access_key_id] ||= Constants::ACCESS_KEY_ID
  conf[:aws_secret_access_key] ||= Constants::SECRET_ACCESS_KEY
  conf[:aws_session_token] ||= Constants::SESSION_TOKEN
  conf[:aws_profile] ||= Constants::PROFILE

  Aws.config.update(region: conf[:aws_region])

  credentials = Aws::Credentials.new(conf[:aws_access_key_id], conf[:aws_secret_access_key], conf[:aws_session_token]) unless conf[:aws_access_key_id].nil?
  credentials = Aws::SharedCredentials.new(profile_name: conf[:aws_profile]) unless conf[:aws_profile].nil?
  credentials = Aws::InstanceProfileCredentials.new if conf[:aws_profile].nil? && conf[:aws_access_key_id].nil?
  raise RubyAemAws::ArgumentError unless defined? credentials

  Aws.config.update(credentials: credentials)

  @aws = AwsCreator.create_aws
end

Instance Method Details

#consolidated(stack_prefix) ⇒ Object

Create a consolidated instance.

Parameters:

  • stack_prefix

    AWS tag: StackPrefix

Returns:

  • new RubyAemAws::ConsolidatedStack instance



73
74
75
76
77
78
79
80
81
82
# File 'lib/ruby_aem_aws.rb', line 73

def consolidated(stack_prefix)
  aws_clients = {
    CloudFormationClient: @aws[:CloudFormationClient],
    CloudWatchClient: @aws[:CloudWatchClient],
    CloudWatchLogsClient: @aws[:CloudWatchLogsClient],
    Ec2Resource: @aws[:Ec2Resource]
  }

  RubyAemAws::ConsolidatedStack.new(stack_prefix, aws_clients)
end

#full_set(stack_prefix) ⇒ Object

Create a full set instance.

Parameters:

  • stack_prefix

    AWS tag: StackPrefix

Returns:

  • new RubyAemAws::FullSetStack instance



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ruby_aem_aws.rb', line 88

def full_set(stack_prefix)
  aws_clients = {
    AutoScalingClient: @aws[:AutoScalingClient],
    CloudFormationClient: @aws[:CloudFormationClient],
    CloudWatchClient: @aws[:CloudWatchClient],
    CloudWatchLogsClient: @aws[:CloudWatchLogsClient],
    Ec2Resource: @aws[:Ec2Resource],
    ElbClient: @aws[:ElbClient]
  }

  RubyAemAws::FullSetStack.new(stack_prefix, aws_clients)
end

#stack_manager(stack_prefix) ⇒ Object

Create Stack Manager resources

Parameters:

  • stack_prefix

    AWS tag: StackPrefix

Returns:

  • new RubyAemAws::StackManager instance



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/ruby_aem_aws.rb', line 105

def stack_manager(stack_prefix)
  aws_clients = {
    CloudFormationClient: @aws[:CloudFormationClient],
    CloudWatchClient: @aws[:CloudWatchClient],
    CloudWatchLogsClient: @aws[:CloudWatchLogsClient],
    DynamoDBClient: @aws[:DynamoDBClient],
    S3Client: @aws[:S3Client],
    S3Resource: @aws[:S3Resource]
  }

  RubyAemAws::StackManager.new(stack_prefix, aws_clients)
end

#test_connectionObject

Test connection to Amazon AWS

Returns:

  • One or more regions that are currently available.



60
61
62
63
64
65
66
67
# File 'lib/ruby_aem_aws.rb', line 60

def test_connection
  result = []
  ec2_client = @aws[:Ec2Client]
  ec2_client.describe_regions.regions.each do |region|
    result.push("Region #{region.region_name} (#{region.endpoint})")
  end
  !result.empty?
end