A Cloudfront Lambda@Edge stack for performing basic auth protection
npm install @aligent/cdk-basic-auth- Enforces Basic Authentication for CloudFront requests.
- Simplified deployment using the BasicAuthFunction construct.
- For usage in CDK projects or alongside Aligent CDK-Constructs
1. Lambda@Edge Handler: Implements the Basic Authentication logic.
2. BasicAuthFunction Construct: A CDK construct for deploying the handler as a Lambda@Edge function.
---
Add the package to your CDK project:npm install @aligent/cdk-basic-auth
``typescript
...
import { BasicAuthFunction, BasicAuthFunctionOptions } from 'your-package-name';
...
export class StaticHostingStack extends Stack {
constructor(scope: Construct, id: string, props: StaticHostingProps) {
super(scope, id, props);
const basicAuthFunction = new BasicAuthFunction(this, 'MyBasicAuthFunction', { username: 'testuser', password: 'password' });
const defaultBehaviorEdgeLambdas: EdgeLambda[] = [];
defaultBehaviorEdgeLambdas.push(
{
eventType: LambdaEdgeEventType.ORIGIN_REQUEST,
functionVersion: basicAuthFunction.edgeFunction.currentVersion
}
);
}
...
`
This is a basic non-functional implementation. See StaticHosting/README.md to cover full usage.
- Invalid Credentials: Responds with 401 Unauthorized.401 Unauthorized` and prompts for Basic Authentication.
- Missing Credentials: Responds with