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
# Example automatically generated from non-compiling source. May contain errors.
from aws_cdk.core import Construct, RemovalPolicy, Stack, StackProps
from aws_cdk.aws_ssm import StringParameter
from aws_cdk.aws_cloudfront import SecurityPolicyProtocol
from cloudcomponents.cdk_static_website import StaticWebsite
from cloudcomponents.cdk_lambda_at_edge_pattern import HttpHeaders
class StaticWebsiteStack(Stack):
def __init__(self, scope, id, *, description=None, env=None, stackName=None, tags=None, synthesizer=None, terminationProtection=None, analyticsReporting=None):
super().__init__(scope, id, description=description, env=env, stackName=stackName, tags=tags, synthesizer=synthesizer, terminationProtection=terminationProtection, analyticsReporting=analyticsReporting)
certificate_arn = StringParameter.value_from_lookup(self, "/certificate/cloudcomponents.org")
website = StaticWebsite(self, "StaticWebsite",
bucket_configuration=WebsiteBucketProps(
removal_policy=RemovalPolicy.DESTROY
),
alias_configuration=AliasProps(
domain_name="cloudcomponents.org",
names=["www.cloudcomponents.org", "cloudcomponents.org"],
acm_cert_ref=certificate_arn
)
)
# A us-east-1 stack is generated under the hood
http_headers = HttpHeaders(self, "HttpHeaders",
http_headers={
"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"
}
)
website.add_lambda_function_association(http_headers)
Cloudfront Distribution
# Example automatically generated from non-compiling source. May contain errors.
cloudfront.Distribution(self, "myDist",
default_behavior={
"origin": origins.S3Origin(my_bucket),
"edge_lambdas": [http_headers]
}
)
Cloudfront WebDistribution
# Example automatically generated from non-compiling source. May contain errors.
cloudfront.CloudFrontWebDistribution(self, "MyDistribution",
origin_configs=[{
"s3_origin_source": {
"s3_bucket_source": source_bucket
},
"behaviors": [{
"is_default_behavior": True,
"lambda_function_associations": [http_headers]
}
]
}
]
)
HttpHeaders
# Example automatically generated from non-compiling source. May contain errors.
http_headers = HttpHeaders(self, "HttpHeaders",
http_headers={
"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/
# Example automatically generated from non-compiling source. May contain errors.
origin_mutation = 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
Close
Hashes for cloudcomponents.cdk-lambda-at-edge-pattern-1.47.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fb7df47c832e107be3da04b70ab62980790c55eff8a3f1a9ba793b202507279 |
|
MD5 | 1c400344cc1f32e604d18c2db5b645ec |
|
BLAKE2b-256 | b818349e0ecde65693c3bd0f03ccf67f5bc31a56ba2ea9e7c051eb6211eeeffe |
Close
Hashes for cloudcomponents.cdk_lambda_at_edge_pattern-1.47.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02b3127b793523e4ffd9da8324c3ede18e56ba36f44cbd3188c0400ce146fa89 |
|
MD5 | 004713f88724549b8ab3088b8b47fdac |
|
BLAKE2b-256 | 98ae5be9e7ebb06c62c23c41f48bb837c41cf0eb8adfa5a8bcb69f84cf55e92b |