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 without compilation. See https://github.com/aws/jsii/issues/826
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):
super().__init__(scope, id, description=description, env=env, stackName=stackName, tags=tags, synthesizer=synthesizer, terminationProtection=terminationProtection)
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 without compilation. See https://github.com/aws/jsii/issues/826
cloudfront.Distribution(self, "myDist",
default_behavior={
"origin": origins.S3Origin(my_bucket),
"edge_lambdas": [http_headers]
}
)
Cloudfront WebDistribution
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
cloudfront.CloudFrontWebDistribution(self, "MyDistribution",
origin_configs=[{
"s3_origin_source": {
"s3_bucket_source": source_bucket
},
"behaviors": [{
"is_default_behavior": True,
"lambda_function_associations": [http_headers]
}
]
}
]
)
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.0.8.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e13dbf648712636a22c5fbb88bf970e57f5bfe00427e36086c054802e40c161f |
|
MD5 | a40608f698a83be4593d77569e3ef489 |
|
BLAKE2b-256 | a98da9608df0d5751b5e42f4b02abb279d0ac38dc461a4e91e2b10185536def4 |
Close
Hashes for cloudcomponents.cdk_lambda_at_edge_pattern-1.0.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59f8351922aa62d9aa4bff57ec05dd09f996b5d9c93f75a227f4a79e68f05023 |
|
MD5 | 73d43566e01b57b278edd388537a5366 |
|
BLAKE2b-256 | f0c7e2a3219459084b7b045d6e432fb755a5e3a675b996f816b869d0b68df153 |