Skip to main content

AwsLambdaExecutionModule

AwsLambdaExecutionModule runs a deployment's container image as a Lambda function in a serverless region, behind a function URL, with its environmentVariables, reservedConcurrency and invokeMode; its memory, timeout and command come from the deployment.

The server and the deployment create nothing; this module creates everything Lambda needs to run them: an IAM role trusting Lambda and holding the server's grants, the function, and a URL that only signed requests may call. The role gets no permission to write logs.

The function runs outside a VPC, so it ignores the server's security group rules. The deployment must name an image octo publishes into ECR, set a memory from 128 to 10240 MiB and a timeout from 1 to 900 seconds, and listen on at most one tcp port. A deployment that does not is rejected before anything is created. The function runs on the processor the image is published for, and the Lambda Web Adapter forwards each request to the deployment's port, as AWS_LWA_PORT.

@cost

Lambda bills each request (about $0.20 per million) and the memory held for as long as each runs (about $0.0000167 per GB-second on x86_64, about a fifth less on arm64), after a free million requests and 400,000 GB-seconds a month. An idle function costs nothing. Its logs bill about $0.50 per GB written to CloudWatch.

@downtime

None for a new deployment or setting: Lambda swaps the code in place, and requests already running finish on the old code. A request arriving after the function was idle waits for a cold start, from a fraction of a second to a few seconds for a container image.

@example

TypeScript

import { type Deployment, type Environment, type Subnet, stub } from '@quadnix/octo';
import { AwsLambdaExecutionModule } from '@quadnix/octo-aws-cdk/modules/execution/aws-lambda-execution';

octo.loadModule(AwsLambdaExecutionModule, 'my-execution-module', {
deployment: stub<Deployment>('${{my-deployment-module.model.deployment}}'),
environment: stub<Environment>('${{my-environment-module.model.environment}}'),
environmentVariables: { LOG_LEVEL: 'info' },
executionId: 'backend-v1-qa',
subnet: stub<Subnet>('${{my-subnet-module.model.subnet}}'),
});
@group

Modules/Execution/AwsLambdaExecution

@limit

A request runs for at most 900 seconds, and at most 60 behind AwsCloudFrontServiceModule. Memory is 128 to 10,240 MiB. A BUFFERED request or response is at most 6 MB; RESPONSE_STREAM streams a larger response.

@limit

Every function of the account in a region shares one concurrency quota, 1,000 requests at once by default and lower on a new account; reservedConcurrency sets part of it aside for this function, and caps it there.

@limit

The function runs outside a VPC: it cannot reach a private subnet, an EFS filesystem or anything else inside one, and the server's security group rules do not apply to it.

@limit

It serves only through a function URL, one request and one response at a time: no websockets and no connection the server keeps open to push to a client. An app that will need live updates polls, or runs on an execution that serves connections, such as AwsEcsExecutionModule.

@limit

The function URL accepts only signed requests (AWS_IAM), so the function is reached through AwsCloudFrontServiceModule or by a caller that signs its requests, never anonymously.

@limit

The log group /aws/lambda/<executionId> must not exist before the first apply, which fails otherwise.

@limit

The function writes its logs as plain text, never as JSON.

@losesData

Nothing: a function holds no data. Its logs are kept for logRetentionInDays and deleted with it.

@replaces

Moving the function to another account or region replaces it, and its URL. Every other change, a new image included, updates it in place.

@see

Hierarchy

Index

Constructors

constructor

  • Parameters

    • moduleId: string

      The ID this module is loaded under.

    Returns AwsLambdaExecutionModule

Properties

readonlyinheritedmoduleId

moduleId: string

The ID this module was loaded under. It scopes everything the module produces, so the same module class can be loaded more than once.

staticreadonlyinheritedMODULE_PACKAGE

MODULE_PACKAGE: string

The package the module is registered under, set by Module.

staticreadonlyinheritedMODULE_SCHEMA

MODULE_SCHEMA: any

The schema of the module's inputs, set by Module.

Methods

onInit

  • Creates the execution, checks its deployment has what Lambda needs, and joins it to the image, buckets and tables it uses.


    Parameters

    Returns Promise<(AwsLambdaExecution | AwsLambdaExecutionOverlay)[]>

inheritedregisterHooks

  • registerHooks(): { postCommitHooks?: PostHookSignature[]; postModelActionHooks?: PostHookSignature[]; postResourceActionHooks?: PostHookSignature[]; preCommitHooks?: PreHookSignature[]; preModelActionHooks?: PreHookSignature[]; preResourceActionHooks?: PreHookSignature[] }
  • To hook custom behavior into Octo's lifecycle for the duration of this module. Override it to return the callbacks you want run.

    @see

    Techniques for Hooks.


    Returns { postCommitHooks?: PostHookSignature[]; postModelActionHooks?: PostHookSignature[]; postResourceActionHooks?: PostHookSignature[]; preCommitHooks?: PreHookSignature[]; preModelActionHooks?: PreHookSignature[]; preResourceActionHooks?: PreHookSignature[] }

    • optionalpostCommitHooks?: PostHookSignature[]
    • optionalpostModelActionHooks?: PostHookSignature[]
    • optionalpostResourceActionHooks?: PostHookSignature[]
    • optionalpreCommitHooks?: PreHookSignature[]
    • optionalpreModelActionHooks?: PreHookSignature[]
    • optionalpreResourceActionHooks?: PreHookSignature[]

registerMetadata

  • Resolves the account and the AWS region this execution runs in.


    Parameters

    Returns Promise<{ awsAccountId: string; awsRegionId: string }>