- Enforces Basic Authentication for CloudFront requests.
- Simplified deployment using the
BasicAuthFunction
construct. - For usage in CDK projects or alongside Aligent CDK-Constructs
- Lambda@Edge Handler: Implements the Basic Authentication logic.
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
...
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
. - Missing Credentials: Responds with
401 Unauthorized
and prompts for Basic Authentication.