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



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

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

#acmObject



96
97
98
99
100
101
# File 'lib/awsclient.rb', line 96

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

#apigatewayObject



103
104
105
106
107
108
# File 'lib/awsclient.rb', line 103

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

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



57
58
59
60
61
62
63
64
65
# File 'lib/awsclient.rb', line 57

def assume_role!(role_name, duration_seconds = 3600)
  role_arn = "arn:aws:iam::#{}: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



110
111
112
113
114
115
# File 'lib/awsclient.rb', line 110

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

#cloudformationObject



117
118
119
120
121
122
# File 'lib/awsclient.rb', line 117

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

#cloudfrontObject



124
125
126
127
128
129
# File 'lib/awsclient.rb', line 124

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

#cloudhsmObject



131
132
133
134
135
136
# File 'lib/awsclient.rb', line 131

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

#cloudsearchObject



138
139
140
141
142
143
# File 'lib/awsclient.rb', line 138

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

#cloudtrailObject



145
146
147
148
149
150
# File 'lib/awsclient.rb', line 145

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

#cloudwatchObject



152
153
154
155
156
157
# File 'lib/awsclient.rb', line 152

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

#cloudwatcheventsObject



159
160
161
162
163
164
# File 'lib/awsclient.rb', line 159

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

#cloudwatchlogsObject



166
167
168
169
170
171
# File 'lib/awsclient.rb', line 166

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

#codecommitObject



173
174
175
176
177
178
# File 'lib/awsclient.rb', line 173

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

#codedeployObject



180
181
182
183
184
185
# File 'lib/awsclient.rb', line 180

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

#codepipelineObject



187
188
189
190
191
192
# File 'lib/awsclient.rb', line 187

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

#cognitoidentityObject



194
195
196
197
198
199
# File 'lib/awsclient.rb', line 194

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

#cognitosyncObject



201
202
203
204
205
206
# File 'lib/awsclient.rb', line 201

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

#configserviceObject



208
209
210
211
212
213
# File 'lib/awsclient.rb', line 208

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

#databasemigrationserviceObject



222
223
224
225
226
227
# File 'lib/awsclient.rb', line 222

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

#datapipelineObject



215
216
217
218
219
220
# File 'lib/awsclient.rb', line 215

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

#devicefarmObject



229
230
231
232
233
234
# File 'lib/awsclient.rb', line 229

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

#directconnectObject



236
237
238
239
240
241
# File 'lib/awsclient.rb', line 236

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

#directoryserviceObject



243
244
245
246
247
248
# File 'lib/awsclient.rb', line 243

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

#dynamodbObject



250
251
252
253
254
255
# File 'lib/awsclient.rb', line 250

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

#dynamodbstreamsObject



257
258
259
260
261
262
# File 'lib/awsclient.rb', line 257

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

#ec2Object



264
265
266
267
268
269
# File 'lib/awsclient.rb', line 264

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

#ecrObject



271
272
273
274
275
276
# File 'lib/awsclient.rb', line 271

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

#ecsObject



278
279
280
281
282
283
# File 'lib/awsclient.rb', line 278

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

#efsObject



285
286
287
288
289
290
# File 'lib/awsclient.rb', line 285

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

#elasticbeanstalkObject



299
300
301
302
303
304
# File 'lib/awsclient.rb', line 299

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

#elasticloadbalancingObject



306
307
308
309
310
311
# File 'lib/awsclient.rb', line 306

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

#elasticsearchserviceObject



320
321
322
323
324
325
# File 'lib/awsclient.rb', line 320

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

#elastictranscoderObject



313
314
315
316
317
318
# File 'lib/awsclient.rb', line 313

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

#emrObject



292
293
294
295
296
297
# File 'lib/awsclient.rb', line 292

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

#firehoseObject



327
328
329
330
331
332
# File 'lib/awsclient.rb', line 327

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

#gameliftObject



334
335
336
337
338
339
# File 'lib/awsclient.rb', line 334

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

#glacierObject



341
342
343
344
345
346
# File 'lib/awsclient.rb', line 341

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

#iamObject



348
349
350
351
352
353
# File 'lib/awsclient.rb', line 348

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

#importexportObject



355
356
357
358
359
360
# File 'lib/awsclient.rb', line 355

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

#inspectorObject



362
363
364
365
366
367
# File 'lib/awsclient.rb', line 362

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

#instance_profile_credentialsObject



53
54
55
# File 'lib/awsclient.rb', line 53

def instance_profile_credentials
  ::Aws::InstanceProfileCredentials.new
end

#iotObject



369
370
371
372
373
374
# File 'lib/awsclient.rb', line 369

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

#iotdataplaneObject



376
377
378
379
380
381
# File 'lib/awsclient.rb', line 376

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

#kinesisObject



390
391
392
393
394
395
# File 'lib/awsclient.rb', line 390

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

#kmsObject



383
384
385
386
387
388
# File 'lib/awsclient.rb', line 383

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

#lambdaObject



397
398
399
400
401
402
# File 'lib/awsclient.rb', line 397

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

#lambdapreviewObject



404
405
406
407
408
409
# File 'lib/awsclient.rb', line 404

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
49
50
51
# File 'lib/awsclient.rb', line 44

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

#machinelearningObject



411
412
413
414
415
416
# File 'lib/awsclient.rb', line 411

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

#marketplacecommerceanalyticsObject



418
419
420
421
422
423
# File 'lib/awsclient.rb', line 418

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

#opsworksObject



425
426
427
428
429
430
# File 'lib/awsclient.rb', line 425

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

#profileObject



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

def profile
  credentials.profile_name
end

#profile=(profile_name) ⇒ Object



79
80
81
82
# File 'lib/awsclient.rb', line 79

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

#profile?Boolean

Returns:

  • (Boolean)


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

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

#rdsObject



432
433
434
435
436
437
# File 'lib/awsclient.rb', line 432

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

#role=(role_name) ⇒ Object



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

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

#route53Object



439
440
441
442
443
444
# File 'lib/awsclient.rb', line 439

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

#route53domainsObject



446
447
448
449
450
451
# File 'lib/awsclient.rb', line 446

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

#s3Object



453
454
455
456
457
458
# File 'lib/awsclient.rb', line 453

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

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



460
461
462
463
464
465
# File 'lib/awsclient.rb', line 460

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

#sesObject



467
468
469
470
471
472
# File 'lib/awsclient.rb', line 467

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

#simpledbObject



509
510
511
512
513
514
# File 'lib/awsclient.rb', line 509

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

#snsObject



474
475
476
477
478
479
# File 'lib/awsclient.rb', line 474

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

#sqsObject



481
482
483
484
485
486
# File 'lib/awsclient.rb', line 481

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

#ssmObject



488
489
490
491
492
493
# File 'lib/awsclient.rb', line 488

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

#storagegatewayObject



516
517
518
519
520
521
# File 'lib/awsclient.rb', line 516

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

#stsObject



495
496
497
498
499
500
# File 'lib/awsclient.rb', line 495

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

#supportObject



523
524
525
526
527
528
# File 'lib/awsclient.rb', line 523

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

#swfObject



502
503
504
505
506
507
# File 'lib/awsclient.rb', line 502

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

#underscored_regionObject



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

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

#wafObject



530
531
532
533
534
535
# File 'lib/awsclient.rb', line 530

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

#workspacesObject



537
538
539
540
541
542
# File 'lib/awsclient.rb', line 537

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