Module: Jets::AwsServices
- Includes:
- GlobalMemoist, StackStatus
- Included in:
- AssetTagHelper, AwsInfo, S3Bucket, Builders::CodeBuilder, Builders::ShimVars::Base, Cfn::Builders::ApiDeploymentBuilder, Cfn::Builders::ApiGatewayBuilder, Cfn::Builders::ApiResourcesBuilder, Cfn::Builders::AuthorizerBuilder, Cfn::Builders::ParentBuilder, Cfn::Ship, Cfn::TemplateSource, Cfn::Upload, Commands::Call, Commands::Call::BaseGuesser, Commands::Clean::Log, Commands::Delete, Commands::StackInfo, Commands::Url, Preheat, Resource::ApiGateway::BasePath::Role, Resource::ApiGateway::RestApi::ChangeDetection, Resource::ApiGateway::RestApi::LogicalId, Resource::ApiGateway::RestApi::Routes::Change, Resource::ApiGateway::RestApi::Routes::Change::Base, Router::State, Stack::Output::Lookup, TmpLoader
- Defined in:
- lib/jets/aws_services/global_memoist.rb,
lib/jets/aws_services.rb,
lib/jets/aws_services/s3_bucket.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 # same client as foo1
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: GlobalMemoist, StackStatus Classes: S3Bucket
Instance Method Summary collapse
- #apigateway ⇒ Object
- #aws_lambda ⇒ Object
-
#aws_options ⇒ Object
Override the AWS retry settings with Jets AWS clients.
- #cfn ⇒ Object
- #dynamodb ⇒ Object
- #logs ⇒ Object
- #s3 ⇒ Object
- #s3_resource ⇒ Object
- #sns ⇒ Object
- #sqs ⇒ Object
- #sts ⇒ Object
Methods included from StackStatus
#lookup, #stack_exists?, #stack_in_progress?
Methods included from GlobalMemoist
Instance Method Details
#apigateway ⇒ Object
18 19 20 |
# File 'lib/jets/aws_services.rb', line 18 def apigateway Aws::APIGateway::Client.new() end |
#aws_lambda ⇒ Object
33 34 35 |
# File 'lib/jets/aws_services.rb', line 33 def aws_lambda Aws::Lambda::Client.new() 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
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/jets/aws_services.rb', line 84 def = { retry_limit: 7, # default: 3 retry_base_delay: 0.6, # default: 0.3 } # See debug logger. Noisy. # Example: # D, [2022-12-02T13:18:55.298788 #26182] DEBUG -- : [Aws::APIGateway::Client 200 0.030837 0 retries] get_method(rest_api_id:"mke40eh6l0",resource_id:"zf8w2m",http_method:"GET") .merge!( log_level: :debug, logger: Logger.new($stdout), ) if ENV['JETS_DEBUG_AWS_SDK'] # https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/debugging.html to enable http_wire_trace # See the HTTP headers and JSON responses. Super noisy. .merge!( http_wire_trace: true, ) if ENV['JETS_DEBUG_AWS_SDK_HTTP_WIRE_TRACE'] end |
#cfn ⇒ Object
23 24 25 |
# File 'lib/jets/aws_services.rb', line 23 def cfn Aws::CloudFormation::Client.new() end |
#dynamodb ⇒ Object
28 29 30 |
# File 'lib/jets/aws_services.rb', line 28 def dynamodb Aws::DynamoDB::Client.new() end |
#logs ⇒ Object
38 39 40 |
# File 'lib/jets/aws_services.rb', line 38 def logs Aws::CloudWatchLogs::Client.new() end |
#s3 ⇒ Object
43 44 45 |
# File 'lib/jets/aws_services.rb', line 43 def s3 Aws::S3::Client.new() end |
#s3_resource ⇒ Object
48 49 50 |
# File 'lib/jets/aws_services.rb', line 48 def s3_resource Aws::S3::Resource.new() end |
#sns ⇒ Object
53 54 55 |
# File 'lib/jets/aws_services.rb', line 53 def sns Aws::SNS::Client.new() end |
#sqs ⇒ Object
58 59 60 |
# File 'lib/jets/aws_services.rb', line 58 def sqs Aws::SQS::Client.new() end |
#sts ⇒ Object
63 64 65 |
# File 'lib/jets/aws_services.rb', line 63 def sts Aws::STS::Client.new() end |