Module: Jets::AwsServices

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

Methods included from StackStatus

#lookup, #stack_exists?, #stack_in_progress?

Methods included from GlobalMemoist

included

Instance Method Details

#apigatewayObject



18
19
20
# File 'lib/jets/aws_services.rb', line 18

def apigateway
  Aws::APIGateway::Client.new
end

#aws_lambdaObject



33
34
35
# File 'lib/jets/aws_services.rb', line 33

def aws_lambda
  Aws::Lambda::Client.new
end

#cfnObject



23
24
25
# File 'lib/jets/aws_services.rb', line 23

def cfn
  Aws::CloudFormation::Client.new
end

#dynamodbObject



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

def dynamodb
  Aws::DynamoDB::Client.new
end

#logsObject



38
39
40
# File 'lib/jets/aws_services.rb', line 38

def logs
  Aws::CloudWatchLogs::Client.new
end

#s3Object



43
44
45
# File 'lib/jets/aws_services.rb', line 43

def s3
  Aws::S3::Client.new
end

#s3_resourceObject



48
49
50
# File 'lib/jets/aws_services.rb', line 48

def s3_resource
  Aws::S3::Resource.new
end

#snsObject



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

def sns
  Aws::SNS::Client.new
end

#sqsObject



58
59
60
# File 'lib/jets/aws_services.rb', line 58

def sqs
  Aws::SQS::Client.new
end

#stsObject



63
64
65
# File 'lib/jets/aws_services.rb', line 63

def sts
  Aws::STS::Client.new
end