inspec/libraries/_aws_connection.rb
Clinton Wolfe c75252ae1c
Rework Integration Testing to Support Multiple Accounts (#128)
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2017-12-15 01:37:36 -05:00

55 lines
1.3 KiB
Ruby

# author: Christoph Hartmann
# This class exists so that we can intercept AWS API connection setup
# and have an opportunity to provide credentials from another mechanism
# (such as a train transport URI) in the future.
#
# We commit to always supporting the standard AWS environment variables.
class AWSConnection
def initialize
creds = nil
if ENV['AWS_PROFILE']
creds = Aws::SharedCredentials.new(profile_name: ENV['AWS_PROFILE'])
else
creds = Aws::Credentials.new(
ENV['AWS_ACCESS_KEY_ID'],
ENV['AWS_SECRET_ACCESS_KEY'],
ENV['AWS_SESSION_TOKEN'],
)
end
opts = {
region: ENV['AWS_REGION'] || ENV['AWS_DEFAULT_REGION'],
credentials: creds,
}
Aws.config.update(opts)
end
def sns_client
@sns_client ||= Aws::SNS::Client.new
end
def cloudwatch_client
@cloudwatch_client ||= Aws::CloudWatch::Client.new
end
def cloudwatch_logs_client
@cloudwatch_logs_client ||= Aws::CloudWatchLogs::Client.new
end
def ec2_resource
@ec2_resource ||= Aws::EC2::Resource.new
end
def ec2_client
@ec2_client ||= Aws::EC2::Client.new
end
def iam_resource
@iam_resource ||= Aws::IAM::Resource.new
end
def iam_client
@iam_client ||= Aws::IAM::Client.new
end
end