feat(lambda): external invoke permissions, function DLQ and scope identity metadata - #45
Closed
andres-nullplatform wants to merge 5 commits into
Closed
feat(lambda): external invoke permissions, function DLQ and scope identity metadata#45andres-nullplatform wants to merge 5 commits into
andres-nullplatform wants to merge 5 commits into
Conversation
map_custom_action had no case for it, so the workflow was unreachable. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
These scripts use return, so `bash <script>` never propagates their exit
code and every assert_failure passed vacuously. Also lowercases log
levels with tr, since ${level,,} aborts on bash 3.2.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Reconciled by AWS CLI scripts on create and update, not by tofu: the scope state holds the placeholder function, so an apply on update would roll back deployed code. delete-scope drops the DLQ inline policy first, or DeleteRole fails. Also adds the provided.al2 runtime. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Lets a service attach an event source mapping to the alias instead of re-deriving names. update-scope backfills pre-existing scopes from AWS. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Also fixes a stale capability table and test paths. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Covers the Spin gaps that live in this repo (CLIEN-1002). The scope covered the function well but not its invocation: Spin's lambdas are triggered by DynamoDB streams, SQS, API Gateway authorizers, EventBridge and S3, none of which the scope could reach.
What's in
triggers.invoke_permissionsin the scope-configuration, reconciled onto themainaliasdead_letter_target_arnattribute, with an IAM grant scoped to that ARNlambda.function_name/function_arn/alias_arn/main_alias/execution_role_*published to the NRNprovided.al2runtimekafka-dlt-manageruses it)Out of scope: the SQS event source mapping and the missing stream ESM parameters (both in the SQS / DynamoDB services — the NRN identity above is their prerequisite), the EventBridge rules themselves (they stay in Spin's Terraform and only need the permission), and gaps 3/4 (VPC overrides, advanced logging), dropped by decision.
Why these run outside Terraform
The scope's tofu run only happens on create/delete. Its state holds the placeholder function while deployments mutate the real one through the AWS CLI, so an
applyon update sees drift and reverts the function to the placeholder — publishing a placeholder version and moving themainalias to it.lifecycle.ignore_changesonaws_lambda_function.mainis currently an empty block, andcompute/lambda/setupalso forcesruntime=nodejs22.xon placeholder-zip deploys, which would break a .NET function regardless.So invoke permissions and the DLQ are reconciled by idempotent AWS CLI scripts that run on both create and update and touch only the field they own. Making
update-scopetofu-driven is real work with its own e2e validation — see Follow-ups.Two safety properties worth reviewing closely:
np-ext-prefix are ever removed.AllowAPIGatewayInvoke,AllowALBInvokeand hand-made statements are untouched (covered by tests).Incidental fixes
update-scopewas unreachable. It declares"type": "custom",map_custom_actionhad no case for it, so it looked for a non-existentupdate-scope.yaml.delete-scopewould have failed once a DLQ existed: IAM refusesDeleteRolewhile unmanaged inline policies remain.cleanup_role_inline_policiesruns before the destroy.return; run asbash <script>,returnis a warning that doesn't stop execution, so the script always exited 0.wait_provisioned_concurrencylooped forever for the same reason — its timeout branch couldn't return out of the poll loop. Locally this was masked byutils/logusing${level,,}, which is a fatal error on bash 3.2 and aborted scripts for the wrong reason.Verification
ok/not ok, per suite, this branch vsmain:mainwait_provisioned_concurrencyNo new failures anywhere; 15 pre-existing ones fixed.
shellcheckclean on everything new,tofu fmtclean on the files touched.Not yet verified end to end against a real AWS account — that's the check that matters for "does not alter code, env vars or the active version of a running lambda". Steps: create a scope with permissions + DLQ, deploy real code, run
update-scopechanging only the permissions, then confirmCodeSha256,Environmentand the alias version are unchanged.Follow-ups (not in this PR)
update-scopecan't apply function configuration (memory, timeout, runtime, layers…); those still land on the next deployment.deployment/tests/scripts/store_nrn_metadata.batspoints at a script that moved) and tests that shell out to the real AWS CLI.deployment/-rooted tofu layout.