Module: Jets::AwsServices
- Includes:
- GlobalMemoist, StackStatus
- Included in:
- AwsHelpers, AwsInfo, S3Bucket, CLI::Base, CLI::Call, CLI::Ci::Info, CLI::Dotenv::Ssm, CLI::Lambda::Function, CLI::Lambda::Lookup, CLI::Waf::Info, Cfn::Builder::Parent::Genesis, Cfn::Resource::S3::JetsBucket, Cfn::Stack, Cfn::Stack::Template, Cfn::Teardown::Bucket, Code, Dotenv, Dotenv::Ssm, Dotenv::Var, Remote::Base, Stack::Outputs
- Defined in:
- lib/jets/aws_services/global_memoist.rb,
lib/jets/aws_services.rb,
lib/jets/aws_services/aws_info.rb,
lib/jets/aws_services/s3_bucket.rb,
lib/jets/aws_services/aws_helpers.rb,
lib/jets/aws_services/stack_status.rb
Overview
We cache the clients globally to avoid re-instantiating them again after the initial Lambda cold start.
Based on: hashrocket.com/blog/posts/implementing-a-macro-in-ruby-for-memoization Except we use a global variable for the cache. So we’ll use the same client across all instances as well as across Lambda executions after the cold-start. Example:
class Foo
def s3
Aws::S3::Client.new
end
global_memoize :s3
end
foo1 = Foo.new
foo2 = Foo.new
foo1.s3
foo2.s3
A prewarmed request after a cold-start will still use the same s3 client instance since it uses the global variable $__memo_methods as the cache.
Defined Under Namespace
Modules: AwsHelpers, GlobalMemoist, StackStatus
Classes: AwsInfo, S3Bucket
Instance Method Summary
collapse
#output_value, #stack_exists?
included, #reset_cache!
Instance Method Details
#apigateway ⇒ Object
20
21
22
|
# File 'lib/jets/aws_services.rb', line 20
def apigateway
Aws::APIGateway::Client.new(aws_options)
end
|
#aws_options ⇒ Object
Override the AWS retry settings with Jets AWS clients.
The aws-sdk-core has exponential backup with this formula:
2 ** c.retries * c.config.retry_base_delay
So the max delay will be 2 ** 7 * 0.6 = 76.8s
Only scoping this to deploy because dont want to affect people’s application that use the aws sdk.
There is also additional rate backoff logic elsewhere, since this is only scoped to deploys.
Useful links:
https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-core/lib/aws-sdk-core/plugins/retry_errors.rb
https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/jets/aws_services.rb', line 102
def aws_options
options = {
retry_limit: 7, retry_base_delay: 0.6, log_level: :info
}
if ENV["JETS_DEBUG_AWS_SDK"]
options[:log_level] = :debug
options[:logger] = Logger.new($stdout)
end
if ENV["JETS_DEBUG_AWS_SDK_HTTP_WIRE_TRACE"]
options[:http_wire_trace] = true
end
options
end
|
#cfn ⇒ Object
31
32
33
|
# File 'lib/jets/aws_services.rb', line 31
def cfn
Aws::CloudFormation::Client.new(aws_options)
end
|
#codebuild ⇒ Object
36
37
38
|
# File 'lib/jets/aws_services.rb', line 36
def codebuild
Aws::CodeBuild::Client.new(aws_options)
end
|
#dynamodb ⇒ Object
41
42
43
|
# File 'lib/jets/aws_services.rb', line 41
def dynamodb
Aws::DynamoDB::Client.new(aws_options)
end
|
#lambda_client ⇒ Object
Also known as:
aws_lambda
25
26
27
|
# File 'lib/jets/aws_services.rb', line 25
def lambda_client
Aws::Lambda::Client.new(aws_options)
end
|
#logs ⇒ Object
46
47
48
|
# File 'lib/jets/aws_services.rb', line 46
def logs
Aws::CloudWatchLogs::Client.new(aws_options)
end
|
#s3 ⇒ Object
51
52
53
|
# File 'lib/jets/aws_services.rb', line 51
def s3
Aws::S3::Client.new(aws_options)
end
|
#s3_resource ⇒ Object
56
57
58
|
# File 'lib/jets/aws_services.rb', line 56
def s3_resource
Aws::S3::Resource.new(aws_options)
end
|
#sns ⇒ Object
61
62
63
|
# File 'lib/jets/aws_services.rb', line 61
def sns
Aws::SNS::Client.new(aws_options)
end
|
#sqs ⇒ Object
76
77
78
|
# File 'lib/jets/aws_services.rb', line 76
def sqs
Aws::SQS::Client.new(aws_options)
end
|
#ssm ⇒ Object
66
67
68
|
# File 'lib/jets/aws_services.rb', line 66
def ssm
Aws::SSM::Client.new(aws_options)
end
|
#sts ⇒ Object
71
72
73
|
# File 'lib/jets/aws_services.rb', line 71
def sts
Aws::STS::Client.new(aws_options)
end
|
#wafv2 ⇒ Object
81
82
83
|
# File 'lib/jets/aws_services.rb', line 81
def wafv2
Aws::WAFV2::Client.new(aws_options)
end
|