Class: Foobara::AWS::CDK::Service
- Inherits:
-
Object
- Object
- Foobara::AWS::CDK::Service
- Defined in:
- lib/foobara/aws/cdk/service.rb
Overview
Synthesises a Plan into Lambda functions behind one HTTP API.
AWS CDK is the caller's dependency (the Ruby CDK, from its preview feed), so it is referenced lazily — Foobara::AWS.plan works without it, which is what lets a build step produce a plan on a machine that has no CDK at all.
service = Foobara::AWS::CDK::Service.new(self, "Api", plan: plan, code_root: "build")
table.grant_read_write_data(service.function("posts"))
It does NOT build artifacts. code_root must already contain one directory
per unit, each with a handler.rb — so synthesis cannot create a route to a
Lambda whose code was never built.
Constant Summary collapse
- DEFAULT_SIZING =
{ memory_size: 1024, timeout_seconds: 10 }.freeze
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#functions ⇒ Object
readonly
Returns the value of attribute functions.
-
#plan ⇒ Object
readonly
Returns the value of attribute plan.
Instance Method Summary collapse
-
#function(name) ⇒ Object
Look a unit's function up by name, for grants: table.grant_read_write_data(service.function("posts")).
-
#initialize(scope, id, plan:, code_root:, sizing: {}, defaults: DEFAULT_SIZING, environment: {}, runtime: nil, architecture: nil, authorizer: nil, api_props: {}, tracing: nil, log_retention: nil) ⇒ Service
constructor
rubocop:disable Metrics/ParameterLists.
- #url ⇒ Object
Constructor Details
#initialize(scope, id, plan:, code_root:, sizing: {}, defaults: DEFAULT_SIZING, environment: {}, runtime: nil, architecture: nil, authorizer: nil, api_props: {}, tracing: nil, log_retention: nil) ⇒ Service
rubocop:disable Metrics/ParameterLists
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/foobara/aws/cdk/service.rb', line 32 def initialize(scope, id, plan:, code_root:, sizing: {}, defaults: DEFAULT_SIZING, environment: {}, runtime: nil, architecture: nil, authorizer: nil, api_props: {}, tracing: nil, log_retention: nil) # Checked first: everything below needs it, and a bare LoadError from # `constructs` would say nothing about which dependency is missing. cdk @scope = construct(scope, id) @plan = plan @code_root = code_root @sizing = sizing.transform_keys(&:to_s) @defaults = DEFAULT_SIZING.merge(defaults) @environment = environment @runtime = runtime @architecture = architecture @tracing = tracing @log_retention = log_retention @functions = {} @api = cdk::APIGatewayv2::HttpAPI.new(@scope, "Api", api_props) @authorizer = () plan.units.each { |unit| add_unit(unit) } end |
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
29 30 31 |
# File 'lib/foobara/aws/cdk/service.rb', line 29 def api @api end |
#functions ⇒ Object (readonly)
Returns the value of attribute functions.
29 30 31 |
# File 'lib/foobara/aws/cdk/service.rb', line 29 def functions @functions end |
#plan ⇒ Object (readonly)
Returns the value of attribute plan.
29 30 31 |
# File 'lib/foobara/aws/cdk/service.rb', line 29 def plan @plan end |
Instance Method Details
#function(name) ⇒ Object
Look a unit's function up by name, for grants:
table.grant_read_write_data(service.function("posts"))
59 |
# File 'lib/foobara/aws/cdk/service.rb', line 59 def function(name) = @functions.fetch(name.to_s) |
#url ⇒ Object
61 |
# File 'lib/foobara/aws/cdk/service.rb', line 61 def url = @api.url |