Class: Awsclient::Connection

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

Constant Summary collapse

SERVICES =
[
  :acm, :apigateway, :autoscaling, :cloudformation, :cloudfront, :cloudhsm,
  :cloudsearch, :cloudtrail, :cloudwatch, :cloudwatchevents, :cloudwatchlogs,
  :codecommit, :codedeploy, :codepipeline, :cognitoidentity, :cognitosync, :configservice,
  :datapipeline, :databasemigrationservice, :devicefarm, :directconnect, :directoryservice,
  :dynamodb, :dynamodbstreams, :ec2, :ecr, :ecs, :efs, :emr, :elasticache, :elasticbeanstalk,
  :elasticloadbalancing, :elastictranscoder, :elasticsearchservice, :firehose, :gamelift, :glacier,
  :iam, :importexport, :inspector, :iot, :iotdataplane, :kms, :kinesis, :lambda, :lambdapreview,
  :machinelearning, :marketplacecommerceanalysis, :opsworks, :rds, :redshift, :route53, :route53domains,
  :s3, :ses, :sns, :sqs, :ssm, :sts, :swf, :simpledb, :storagegateway, :support, :waf, :workspaces
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_options = {}) ⇒ Connection

Returns a new instance of Connection.



28
29
30
# File 'lib/awsclient.rb', line 28

def initialize(client_options = {})
  self.client_options = client_options
end

Instance Attribute Details

#client_optionsObject

Returns the value of attribute client_options.



8
9
10
# File 'lib/awsclient.rb', line 8

def client_options
  @client_options
end

#credentialsObject

Returns the value of attribute credentials.



9
10
11
# File 'lib/awsclient.rb', line 9

def credentials
  @credentials
end

#regionObject

Returns the value of attribute region.



10
11
12
# File 'lib/awsclient.rb', line 10

def region
  @region
end

Instance Method Details

#account_idObject



88
89
90
# File 'lib/awsclient.rb', line 88

def 
  iam.get_user.user.arn.split(':')[4]
end

#acmObject



92
93
94
95
96
97
# File 'lib/awsclient.rb', line 92

def acm
  @acm ||= ::Aws::ACM::Client.new(
    credentials: credentials,
    region: region
  )
end

#apigatewayObject



99
100
101
102
103
104
# File 'lib/awsclient.rb', line 99

def apigateway
  @apigateway ||= ::Aws::APIGateway::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#assume_role!(role_name, duration_seconds = 3600) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/awsclient.rb', line 54

def assume_role!(role_name, duration_seconds = 3600)
  role_arn = "arn:aws:iam::#{account_id}:role/#{role_name}"
  self.credentials = ::Aws::AssumeRoleCredentials.new(
    client: sts,
    role_arn: role_arn,
    role_session_name: random_string(32),
    duration_seconds: duration_seconds
  )
end

#autoscalingObject



106
107
108
109
110
111
# File 'lib/awsclient.rb', line 106

def autoscaling
  @autoscaling ||= ::Aws::AutoScaling::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#cloudformationObject



113
114
115
116
117
118
# File 'lib/awsclient.rb', line 113

def cloudformation
  @cloudformation ||= ::Aws::CloudFormation::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#cloudfrontObject



120
121
122
123
124
125
# File 'lib/awsclient.rb', line 120

def cloudfront
  @cloudformation ||= ::Aws::CloudFront::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#cloudhsmObject



127
128
129
130
131
132
# File 'lib/awsclient.rb', line 127

def cloudhsm
  @cloudformation ||= ::Aws::CloudHSM::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#cloudsearchObject



134
135
136
137
138
139
# File 'lib/awsclient.rb', line 134

def cloudsearch
  @cloudformation ||= ::Aws::CloudSearch::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#cloudtrailObject



141
142
143
144
145
146
# File 'lib/awsclient.rb', line 141

def cloudtrail
  @cloudtrail ||= ::Aws::CloudTrail::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#cloudwatchObject



148
149
150
151
152
153
# File 'lib/awsclient.rb', line 148

def cloudwatch
  @cloudwatch ||= ::Aws::CloudWatch::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#cloudwatcheventsObject



155
156
157
158
159
160
# File 'lib/awsclient.rb', line 155

def cloudwatchevents
  @cloudwatchevents ||= ::Aws::CloudWatchEvents::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#cloudwatchlogsObject



162
163
164
165
166
167
# File 'lib/awsclient.rb', line 162

def cloudwatchlogs
  @cloudwatchlogs ||= ::Aws::CloudWatchLogs::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#codecommitObject



169
170
171
172
173
174
# File 'lib/awsclient.rb', line 169

def codecommit
  @codecommit ||= ::Aws::CodeCommit::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#codedeployObject



176
177
178
179
180
181
# File 'lib/awsclient.rb', line 176

def codedeploy
  @codedeploy ||= ::Aws::CodeDeploy::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#codepipelineObject



183
184
185
186
187
188
# File 'lib/awsclient.rb', line 183

def codepipeline
  @codepipeline ||= ::Aws::CodePipeline::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#cognitoidentityObject



190
191
192
193
194
195
# File 'lib/awsclient.rb', line 190

def cognitoidentity
  @cognitoidentity ||= ::Aws::CognitoIdentity::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#cognitosyncObject



197
198
199
200
201
202
# File 'lib/awsclient.rb', line 197

def cognitosync
  @cognitosync ||= ::Aws::CognitoSync::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#configserviceObject



204
205
206
207
208
209
# File 'lib/awsclient.rb', line 204

def configservice
  @codedeploy ||= ::Aws::ConfigService::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#databasemigrationserviceObject



218
219
220
221
222
223
# File 'lib/awsclient.rb', line 218

def databasemigrationservice
  @databasemigrationservice ||= ::Aws::DatabaseMigrationService::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#datapipelineObject



211
212
213
214
215
216
# File 'lib/awsclient.rb', line 211

def datapipeline
  @datapipeline ||= ::Aws::DataPipeline::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#devicefarmObject



225
226
227
228
229
230
# File 'lib/awsclient.rb', line 225

def devicefarm
  @devicefarm ||= ::Aws::DeviceFarm::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#directconnectObject



232
233
234
235
236
237
# File 'lib/awsclient.rb', line 232

def directconnect
  @directconnect ||= ::Aws::DirectConnect::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#directoryserviceObject



239
240
241
242
243
244
# File 'lib/awsclient.rb', line 239

def directoryservice
  @directoryservice ||= ::Aws::DirectoryService::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#dynamodbObject



246
247
248
249
250
251
# File 'lib/awsclient.rb', line 246

def dynamodb
  @dynamodb ||= ::Aws::DynamoDB::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#dynamodbstreamsObject



253
254
255
256
257
258
# File 'lib/awsclient.rb', line 253

def dynamodbstreams
  @dynamodbstreams ||= ::Aws::DynamoDBStreams::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#ec2Object



260
261
262
263
264
265
# File 'lib/awsclient.rb', line 260

def ec2
  @ec2 ||= ::Aws::EC2::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#ecrObject



267
268
269
270
271
272
# File 'lib/awsclient.rb', line 267

def ecr
  @ecr ||= ::Aws::ECR::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#ecsObject



274
275
276
277
278
279
# File 'lib/awsclient.rb', line 274

def ecs
  @ecs ||= ::Aws::ECS::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#efsObject



281
282
283
284
285
286
# File 'lib/awsclient.rb', line 281

def efs
  @efs ||= ::Aws::EFS::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#elasticbeanstalkObject



295
296
297
298
299
300
# File 'lib/awsclient.rb', line 295

def elasticbeanstalk
  @elasticbeanstalk ||= ::Aws::ElasticBeanstalk::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#elasticloadbalancingObject



302
303
304
305
306
307
# File 'lib/awsclient.rb', line 302

def elasticloadbalancing
  @elasticloadbalancing ||= ::Aws::ElasticLoadBalancing::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#elasticsearchserviceObject



316
317
318
319
320
321
# File 'lib/awsclient.rb', line 316

def elasticsearchservice
  @elasticsearchservice ||= ::Aws::ElasticsearchService::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#elastictranscoderObject



309
310
311
312
313
314
# File 'lib/awsclient.rb', line 309

def elastictranscoder
  @elastictranscoder ||= ::Aws::ElasticTranscoder::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#emrObject



288
289
290
291
292
293
# File 'lib/awsclient.rb', line 288

def emr
  @emr ||= ::Aws::EMR::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#firehoseObject



323
324
325
326
327
328
# File 'lib/awsclient.rb', line 323

def firehose
  @firehose ||= ::Aws::Firehose::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#gameliftObject



330
331
332
333
334
335
# File 'lib/awsclient.rb', line 330

def gamelift
  @gamelift ||= ::Aws::GameLift::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#glacierObject



337
338
339
340
341
342
# File 'lib/awsclient.rb', line 337

def glacier
  @glacier ||= ::Aws::Glacier::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#iamObject



344
345
346
347
348
349
# File 'lib/awsclient.rb', line 344

def iam
  @iam ||= ::Aws::IAM::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#importexportObject



351
352
353
354
355
356
# File 'lib/awsclient.rb', line 351

def importexport
  @importexport ||= ::Aws::ImportExport::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#inspectorObject



358
359
360
361
362
363
# File 'lib/awsclient.rb', line 358

def inspector
  @importexport ||= ::Aws::Inspector::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#instance_profile_credentialsObject



50
51
52
# File 'lib/awsclient.rb', line 50

def instance_profile_credentials
  ::Aws::InstanceProfileCredentials.new
end

#iotObject



365
366
367
368
369
370
# File 'lib/awsclient.rb', line 365

def iot
  @iot ||= ::Aws::IoT::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#iotdataplaneObject



372
373
374
375
376
377
# File 'lib/awsclient.rb', line 372

def iotdataplane
  @iotdataplane ||= ::Aws::IoTDataPlane::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#kinesisObject



386
387
388
389
390
391
# File 'lib/awsclient.rb', line 386

def kinesis
  @kinesis ||= ::Aws::Kinesis::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#kmsObject



379
380
381
382
383
384
# File 'lib/awsclient.rb', line 379

def kms
  @kms ||= ::Aws::KMS::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#lambdaObject



393
394
395
396
397
398
# File 'lib/awsclient.rb', line 393

def lambda
  @lambda ||= ::Aws::Lambda::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#lambdapreviewObject



400
401
402
403
404
405
# File 'lib/awsclient.rb', line 400

def lambdapreview
  @lambdapreview ||= ::Aws::LambdaPreview::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#load_credentials(profile_name = 'default') ⇒ Object



44
45
46
47
48
# File 'lib/awsclient.rb', line 44

def load_credentials(profile_name='default')
  creds = ::Aws::SharedCredentials.new(profile_name: profile_name)
  return creds if creds.set?
  instance_profile_credentials
end

#machinelearningObject



407
408
409
410
411
412
# File 'lib/awsclient.rb', line 407

def machinelearning
  @machinelearning ||= ::Aws::MachineLearning::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#marketplacecommerceanalyticsObject



414
415
416
417
418
419
# File 'lib/awsclient.rb', line 414

def marketplacecommerceanalytics
  @marketplacecommerceanalytics ||= ::Aws::MarketplaceCommerceAnalytics::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#profileObject



72
73
74
# File 'lib/awsclient.rb', line 72

def profile
  credentials.profile_name
end

#profile=(profile_name) ⇒ Object



76
77
78
# File 'lib/awsclient.rb', line 76

def profile=(profile_name)
  self.credentials = ::Aws::SharedCredentials.new(profile_name: profile_name)
end

#profile?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/awsclient.rb', line 68

def profile?
  credentials.respond_to?(:profile_name)
end

#rdsObject



421
422
423
424
425
426
# File 'lib/awsclient.rb', line 421

def rds
  @rds ||= ::Aws::RDS::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#role=(role_name) ⇒ Object



64
65
66
# File 'lib/awsclient.rb', line 64

def role=(role_name)
  assume_role!(role_name)
end

#route53Object



428
429
430
431
432
433
# File 'lib/awsclient.rb', line 428

def route53
  @route53 ||= ::Aws::Route53::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#route53domainsObject



435
436
437
438
439
440
# File 'lib/awsclient.rb', line 435

def route53domains
  @route53domains ||= ::Aws::Route53Domains::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#s3Object



442
443
444
445
446
447
# File 'lib/awsclient.rb', line 442

def s3
  @s3 ||= ::Aws::S3::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#s3_bucket(name, options = {}) ⇒ Object



449
450
451
452
453
454
# File 'lib/awsclient.rb', line 449

def s3_bucket(name, options = {})
  @bucket ||= ::Aws::S3::Bucket.new(name, {
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#sesObject



456
457
458
459
460
461
# File 'lib/awsclient.rb', line 456

def ses
  @ses ||= ::Aws::SES::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#simpledbObject



498
499
500
501
502
503
# File 'lib/awsclient.rb', line 498

def simpledb
  @simpledb ||= ::Aws::SimpleDB::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#snsObject



463
464
465
466
467
468
# File 'lib/awsclient.rb', line 463

def sns
  @sns ||= ::Aws::SNS::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#sqsObject



470
471
472
473
474
475
# File 'lib/awsclient.rb', line 470

def sqs
  @sqs ||= ::Aws::SQS::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#ssmObject



477
478
479
480
481
482
# File 'lib/awsclient.rb', line 477

def ssm
  @ssm ||= ::Aws::SSM::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#storagegatewayObject



505
506
507
508
509
510
# File 'lib/awsclient.rb', line 505

def storagegateway
  @storagegateway ||= ::Aws::StorageGateway::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#stsObject



484
485
486
487
488
489
# File 'lib/awsclient.rb', line 484

def sts
  @sts ||= ::Aws::STS::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#supportObject



512
513
514
515
516
517
# File 'lib/awsclient.rb', line 512

def support
  @support ||= ::Aws::Support::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#swfObject



491
492
493
494
495
496
# File 'lib/awsclient.rb', line 491

def swf
  @swf ||= ::Aws::SWF::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#underscored_regionObject



84
85
86
# File 'lib/awsclient.rb', line 84

def underscored_region
  region.gsub('-', '_')
end

#wafObject



519
520
521
522
523
524
# File 'lib/awsclient.rb', line 519

def waf
  @waf ||= ::Aws::WAF::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end

#workspacesObject



526
527
528
529
530
531
# File 'lib/awsclient.rb', line 526

def workspaces
  @workspaces ||= ::Aws::WorkSpaces::Client.new({
    credentials: credentials,
    region: region
  }.merge(client_options))
end