CDK Constructs for Lambda@Edge pattern: HttpHeaders
Project description
@cloudcomponents/cdk-lambda-at-edge-pattern
CDK Constructs for Lambda@Edge pattern: HttpHeaders
Install
TypeScript/JavaScript:
npm i @cloudcomponents/cdk-lambda-at-edge-pattern
Python:
pip install cloudcomponents.cdk-lambda-at-edge-pattern
How to use
import { StaticWebsite } from '@cloudcomponents/cdk-static-website';
import { OriginMutation } from '@cloudcomponents/cdk-lambda-at-edge-pattern';
import { RemovalPolicy, Stack, StackProps, aws_route53 } from 'aws-cdk-lib';
import { Construct } from 'constructs';
export class StaticWebsiteStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps) {
super(scope, id, props);
const hostedZone = aws_route53.HostedZone.fromLookup(this, 'HostedZone', {
domainName: 'cloudcomponents.org',
});
// Create a lambda at edge
const originMutation = new OriginMutation(stack, 'OriginMutation');
new StaticWebsite(this, 'StaticWebsite', {
hostedZone,
domainNames: ['cloudcomponents.org', 'www.cloudcomponents.org'],
edgeLambdas: [originMutation],
removalPolicy: RemovalPolicy.DESTROY,
});
}
}
Cloudfront Distribution
new cloudfront.Distribution(this, 'myDist', {
defaultBehavior: {
origin: new origins.S3Origin(myBucket),
edgeLambdas: [httpHeaders],
},
});
HttpHeaders
const httpHeaders = new HttpHeaders(this, 'HttpHeaders', {
httpHeaders: {
'Content-Security-Policy':
"default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; object-src 'none'; connect-src 'self'",
'Strict-Transport-Security':
'max-age=31536000; includeSubdomains; preload',
'Referrer-Policy': 'same-origin',
'X-XSS-Protection': '1; mode=block',
'X-Frame-Options': 'DENY',
'X-Content-Type-Options': 'nosniff',
'Cache-Control': 'no-cache',
},
});
OriginMutation
https://chrisschuld.com/2020/05/gatsby-hosting-on-cloudfront/
const originMutation = new OriginMutation(stack, 'OriginMutation');
API Reference
See API.md.
Example
See more complete examples.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cloudcomponents.cdk-lambda-at-edge-pattern-2.4.0.tar.gz
.
File metadata
- Download URL: cloudcomponents.cdk-lambda-at-edge-pattern-2.4.0.tar.gz
- Upload date:
- Size: 538.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d85f89081b17593f90b6abf6f2c89eeef4009f5911d230e2ade04a126037d98 |
|
MD5 | a2be7074edd77b7744ecbfd79146592b |
|
BLAKE2b-256 | 7f5f6926288fcb3a322a9e8d22cc4b80feb120e704fa19a44f5584e133ca2b91 |
File details
Details for the file cloudcomponents.cdk_lambda_at_edge_pattern-2.4.0-py3-none-any.whl
.
File metadata
- Download URL: cloudcomponents.cdk_lambda_at_edge_pattern-2.4.0-py3-none-any.whl
- Upload date:
- Size: 537.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f49878012237b5ccdca10c01e4d3fb3a441fe9ff40ee8348f47f035ac8936fec |
|
MD5 | 7843d87fb6b471cbc60fbe9842c9383b |
|
BLAKE2b-256 | 0ebd7b3c6361162a21d0d5a64afb6c3f06fc0cdff1ecfcc169cdd927e43f6cec |