@beesolve/lambda-function-url-protection
v0.2.0
Published
Fail-closed origin-token protection for a Lambda Function URL behind CloudFront. A secret is generated and sent as the `x-origin-token` header from CloudFront, injected into the handler as `ORIGIN_TOKEN`, and verified at runtime so the Function URL cannot
Readme
Lambda Function URL Protection
Fail-closed origin-token protection for a Lambda Function URL behind CloudFront. A secret is generated and sent as the x-origin-token header from CloudFront, injected into the handler as ORIGIN_TOKEN, and verified at runtime so the Function URL cannot be invoked directly, bypassing the distribution.
Installation
npm i @beesolve/lambda-function-url-protectionAPI
CDK side (the . export):
protectedFunctionUrlOrigin(props)- generates the secret, injectsORIGIN_TOKEN, creates the Function URL, and returns a CloudFront origin that sends thex-origin-tokenheader.ProtectedFunctionUrlOriginProps- props for the helper (handler, optionalinvokeMode, optionalallowedOrigins).
Runtime side (the ./runtime export):
protectFetch(fetch)- wraps aFetchhandler, rejecting requests without a matching token with a 403.protectHandler(handler)- wraps a Lambda proxy handler, rejecting events without a matching token with a 403.
See DOCS.md for how-to guides.
