Module: Foobara::AWS::Lambda

Defined in:
lib/foobara/aws/lambda.rb

Overview

Declares how a command should be RUN, next to the command that says what it does:

class DestroyPost < Foobara::Command
extend Foobara::AWS::Lambda
aws_lambda vcpu: 1, timeout: 60
...
end

This is the one thing a manifest cannot otherwise supply. Foobara describes what a command IS, not how it should be run — a defensible line, but something has to carry it, and the person who knows a command fans out across a whole comment tree is the person writing the command.

No change to Foobara is needed: a command's manifest is super.merge(...), so this adds a key and the connector serves it. plan reads it back, and Service sizes each function from it.

ON vcpu. Lambda has no CPU setting — CPU is allocated in proportion to memory, and 1769 MB is the point at which a function gets one full vCPU. So vcpu: is a more honest way to ask for compute than picking a memory number, but it RESOLVES to memory; it is not a second dial. Give both and the larger memory wins, because undersizing is a runtime failure while oversizing is a rounding error on the bill.

Constant Summary collapse

MEMORY_PER_VCPU =

AWS's own figure: one vCPU is allocated at 1,769 MB.

1769
MEMORY_RANGE =

Lambda's floor and ceiling. Asking outside them fails at deploy time, which is a slow way to learn about a typo.

(128..10_240)
TIMEOUT_RANGE =
(1..900)

Instance Method Summary collapse

Instance Method Details

#aws_lambda(memory: nil, vcpu: nil, timeout: nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/foobara/aws/lambda.rb', line 38

def aws_lambda(memory: nil, vcpu: nil, timeout: nil)
  memory = resolve_memory(memory, vcpu)

  if memory && !MEMORY_RANGE.cover?(memory)
    raise ArgumentError, "aws_lambda memory #{memory} outside Lambda's #{MEMORY_RANGE}"
  end
  if timeout && !TIMEOUT_RANGE.cover?(timeout)
    raise ArgumentError, "aws_lambda timeout #{timeout} outside Lambda's #{TIMEOUT_RANGE} seconds"
  end

  @aws_lambda = { "memory_size" => memory, "timeout_seconds" => timeout }.compact
end

#aws_lambda_manifestObject



51
# File 'lib/foobara/aws/lambda.rb', line 51

def aws_lambda_manifest = @aws_lambda

#foobara_manifestObject



53
54
55
56
# File 'lib/foobara/aws/lambda.rb', line 53

def foobara_manifest
  manifest = super
  @aws_lambda ? manifest.merge(aws_lambda: @aws_lambda) : manifest
end