Central-CDN Implementation
We provide a npm package for the central-cdn auth-checker (utilizing the dev-authenticator) to be used in lambda@edge and cdk.
Lambda@Edge Usage
// index.ts
import { addAuthenticationMiddleware, createApp, handler as honoHandler } from '@pit-shared/central-cdn-auth-checker'
const app = createApp()
// add other middlewares before the auth handler
// ...
addAuthenticationMiddleware(app) // the auth middleware must be the last middleware as it doesnt call next()
export const handler = honoHandler(app)
CDK
we also provide the CDK setup, inside your CDK stack import the function and call it:
import { CentralCdnAuthChecker } from '@pit-shared/central-cdn-auth-checker/cdk'
//...
const authLambda = new CentralCdnAuthChecker(this, 'cdn-auth-checker', {
code: './path/to/your/lambda', // or leave empty to use the default function code
})
//...
using a custom code path requires that the bundled output resides in
./path/to/your/lambda/distand a npm commandbuildexists for bundling your custom code.