point-out/lambda-ts is a NestJS app shipped as one container image that
runs as two Lambda functions:
- The HTTP API (
dist/main.handler) atingest.<root_domain>. - The job worker (
dist/main.jobHandler), fed{kind, payload}messages from SQS.
The lambda-ts/ module, called once from modules.tf, holds all of it: the image registry, the CI deploy role, the
functions, the job queue, the ping schedule and the API's distribution.
Architecture
Both functions run the image ECR lambda-ts:<first 7 characters of the deployed branch's head commit>, on arm64.
Their roles hold only what this stack creates: their own log group, and for the worker, the job queue.
Functions
lambda-ts | lambda-ts-worker | |
|---|---|---|
| Command | the image's default, dist/main.handler | dist/main.jobHandler |
| Memory, timeout | 1024 MB, 60 s (CloudFront's origin read timeout) | 1024 MB, 900 s; 2048 MB of /tmp |
| Invoked by | its function URL, behind the distribution | lambda-ts-jobs: batch size 1, at most 5 at a time |
| Role | lambda-ts-lambda: its log group | lambda-ts-worker-lambda: its log group, the job queue |
| Logs | /aws/lambda/lambda-ts, 14 days | /aws/lambda/lambda-ts-worker, 14 days |
The worker's mapping uses the ReportBatchItemFailures response type: jobHandler reports a failed job instead of
throwing, and without that response type SQS would delete the failed message. As a result, the worker's Lambda
Errors metric stays at zero when jobs fail; the DLQ shows the failures.
The batch size is 1 because a batch runs its jobs one after the other, and one job can take the whole 900 s.
Job queue
| Queue | Visibility | Retention | Redrive |
|---|---|---|---|
lambda-ts-jobs | 900 s | 4 days | lambda-ts-jobs-dlq after 3 receives |
lambda-ts-jobs-dlq | 14 days |
Both are standard queues, encrypted with SSE-SQS. A job that keeps failing, or times out, lands in the DLQ after three
tries. To run it again, move the DLQ back with SQS's own redrive (aws sqs start-message-move-task).
Ping schedule
The stack starts one thing on its own: lambda-ts/ping, an EventBridge Scheduler schedule.
- What it sends:
{"kind":"ping","payload":{"at":"<aws.scheduler.scheduled-time>"}}tolambda-ts-jobsevery hour. The scheduler fills in the time. - What happens: the worker runs the
pingjob, which logspingwith that time. An hourlypingin the worker's logs shows the schedule, the queue and the worker work. - Role: the schedule's role,
lambda-ts-scheduler, can only send to the job queue.
Every other job runs only when something sends its message to the queue (see Running a job by hand).
Placeholders
The other jobs read data stores this account does not have: OpenSearch and its rate-limited bulk queue, Redshift, Aurora, the article and FTP buckets, and the author descriptions queue. Those jobs are being reworked away from those stores. Until then:
- Data stores: the worker gets placeholder values for them (
placeholder_environmentinlambda-ts/main.tf), and a job that reads one fails. - Ingest:
INGEST_VALIDATION_ONLYistrue, soPOST /ingestvalidates records and delivers nothing.
HTTP API
| Setting | Value |
|---|---|
| Host | ingest.<root_domain>, A and AAAA alias records to the distribution |
| Certificate | ACM in us-east-1, validated with a DNS record in the zone; replaced before it is destroyed |
| Distribution | origin the function URL over HTTPS (TLS 1.2), origin read timeout 60 s, PriceClass_100, IPv6 on |
| Caching | managed CachingDisabled (it is also what forwards Authorization), managed AllViewerExceptHostHeader |
| Headers | a response headers policy adding HSTS, nosniff, X-Frame-Options: DENY and a referrer policy the app did not set |
The function URL is public (authorization_type = NONE), so the app has two gates.
- Origin secret: the distribution adds a random 64-character
x-origin-secretheader to every origin request, and the app gets the same value asORIGIN_SECRET. A request without it gets a 403 before any route runs. - Bearer token: every route except
GET /then needsAuthorization: Bearer <token>. The token is an AWS IAM outbound identity federation JWT for the audiencehttps://ingest.<root_domain>.
outbound-federation.tf turns outbound federation on for the account. Its issuer's
/.well-known/jwks.json is the API's AUTH_JWKS.
Callers are listed in the module's clients (lambda-ts/clients.tf), as role name → AWS account ID:
- Each entry creates a role here that only that account can assume.
- The role can only mint tokens for the API's audience.
- Its ARN joins
AUTHORIZED_ROLES.
The list is empty today, so no token is accepted.
Deployment
-
Build. A push to
staging(staging) ormain(production) ofpoint-out/lambda-tsruns itsbuild-and-push-lambda.ymlin the GitHub environment of the same name. The job:- assumes
github-actions-lambda-ts-role; - builds
.docker/prod/Dockerfilefor arm64; - pushes the image as
:<sha7>and:latest.
- assumes
-
Deploy. Every apply of this stack does the deploy. It reads the head commit of the environment's branch through the GitHub provider:
mainfor production, otherwise the branch named after the environment. It then sets both functions' image to:<sha7>.Nothing in lambda-ts triggers an apply. The next apply here (a merge into this repository's
staging, orapply.ymlby hand) picks up whatever its branch's head is then. An apply that runs before that commit's build has pushed fails on the functions: the image does not exist yet.
The registry's tags are immutable except latest, and it keeps the last 30 images. Thirty pushes without an apply
would expire the image the functions run. To roll back, revert the branch, let CI build, and apply.
lambda-ts's production.yml is off (if: false), like production here, until the production account exists.
First deploy of an environment
The functions need an image, and CI needs the registry and deploy role from this stack. So the first apply of an
environment fails on the two functions (Source image …:<sha7> does not exist).
If the GitHub environment already has AWS_ROLE, AWS_REGION or AWS_ECR_REPO, the first apply also fails on each
of them with 409 Already exists - Variable already exists. The previous Point-out stack set them for its own
accounts (see GitHub resources).
- Hand the environment's variables over from the previous stack: remove them from its state (below), then delete
them in
point-out/lambda-ts→ Settings → Environments →<env>. - Apply. This creates the registry, the deploy role and the three variables; only the functions fail.
- Run the build of the environment's branch of
point-out/lambda-ts, push or re-run. CI pushes to whateverAWS_ROLEandAWS_ECR_REPOsay when it runs, so a build that ran before step 2 went to the previous account and must run again. - Apply again.
The certificate validates through the zone, so the zone must already be delegated (DNS).
Deploy role
| Name | github-actions-lambda-ts-role |
| Trusted identity | the account's GitHub OIDC provider, audience sts.amazonaws.com |
| Subject | repo:point-out/lambda-ts:environment:<env>: the name-only form, since the repository has not opted into GitHub's id-qualified subjects |
ecr:GetAuthorizationToken | * |
| Push and pull layers and images | the lambda-ts repository |
The role can only push images. What runs is what an apply of this stack sets.
GitHub resources
Managed by the terraform-point-out App, which is installed on every repository of the organization, once per
environment.
| Resource | In | Value |
|---|---|---|
github_repository_environment.main | point-out/lambda-ts | environment <env>, no branch policy |
github_actions_environment_variable.main | point-out/lambda-ts, environment <env> | AWS_ROLE, AWS_REGION, AWS_ECR_REPO |
data.github_branch.deployed | point-out/lambda-ts | the head of the environment's branch |
Hand-over from the previous stack
The previous Point-out stack (the old layout of this repository, lambdas/ts/repository.tf) manages the same
environments and variables of point-out/lambda-ts for its own accounts. The variable names are the same, so only one
stack can own them at a time.
| Environment | AWS_ROLE / AWS_ECR_REPO point to | Owned by |
|---|---|---|
staging | 468351713122 (this stack's staging), since 2026-11-19 | this stack. The previous stack still has them in its state (see below) |
production | 418295703085 (the previous production account) | the previous stack, with a custom deployment branch policy |
Until the previous stack lets go, its next apply in an environment rewrites the variables to its own account, and destroying it deletes the environment. In the previous stack, remove each of these from its state without destroying them:
removed {
from = module.lambdas.module.ts.github_repository_environment.lambda
lifecycle { destroy = false }
}
# … and likewise github_actions_environment_variable.lambda_role, .lambda_region and .lambda_ecr_repo.state rm on the same addresses works too. Do it for staging now. Do it for production before
production's first apply here. The previous stack restricts production's environment to custom branches, and
github_repository_environment.main sets no policy, so this stack's first apply would drop that restriction. Add a
deployment_branch_policy to it first if production should keep one.
Running a job by hand
Send its message to the job queue (output jobs_queue_url of module.lambda_ts):
aws sqs send-message --queue-url https://sqs.eu-central-1.amazonaws.com/<account>/lambda-ts-jobs \
--message-body '{"kind":"ping","payload":{"at":"by hand"}}'