Skip to main content

CDK Constructs for Lambda@Edge pattern: HttpHeaders

Project description

cloudcomponents Logo

@cloudcomponents/cdk-lambda-at-edge-pattern

Build Status cdkdx typescript python

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]
        }
        ]
    }
    ]
)

##APIReference

See [API.md](https, #, #, Example, See, more, complete [examples](https, #, #, License

    [MIT](https)))

Project details


Release history Release notifications | RSS feed

This version

1.0.4

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

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file cloudcomponents.cdk-lambda-at-edge-pattern-1.0.4.tar.gz.

File metadata

  • Download URL: cloudcomponents.cdk-lambda-at-edge-pattern-1.0.4.tar.gz
  • Upload date:
  • Size: 379.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.7

File hashes

Hashes for cloudcomponents.cdk-lambda-at-edge-pattern-1.0.4.tar.gz
Algorithm Hash digest
SHA256 51fa8c885ce61ffd4830ec5e15511e0a45fc52d81da2993c7e32c33aee89c7fb
MD5 63f413b1e083cd9af3dd4f913634f789
BLAKE2b-256 d6141512c7b6f79be8a04a0f07518bc41d443f887d68c085ab3e813d60c22170

See more details on using hashes here.

File details

Details for the file cloudcomponents.cdk_lambda_at_edge_pattern-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for cloudcomponents.cdk_lambda_at_edge_pattern-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fa78991d85edf6eff87cdda8292b4e227781b3ac54c93e504a68446630b2af80
MD5 454f8bdbb0e46163ffe9a917f1990ed0
BLAKE2b-256 72dd9cfc7bcd9c7fdf7105247f02030fb11d0c0cf2373120fd716d640d2adf11

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page