Cdk component that creates a static website using S3, configures CloudFront (CDN) and maps a custom domain via Route53 (DNS)
Project description
@cloudcomponents/cdk-static-website
Cdk component that creates a static website using S3, configures CloudFront (CDN) and maps a custom domain via Route53 (DNS)
Install
TypeScript/JavaScript:
npm i @cloudcomponents/cdk-static-website
Python:
pip install cloudcomponents.cdk-static-website
How to use
Example 1: With an existing certificate
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from aws_cdk.core import Construct, Stack, StackProps, RemovalPolicy
from aws_cdk.aws_ssm import StringParameter
from cloudcomponents.cdk_static_website import StaticWebsite
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")
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
)
)
Example 2: Cloudfront URL with existing sources and up to date Securitypolicy
# 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 cloudcomponents.cdk_static_website import StaticWebsite
from aws_cdk.aws_cloudfront import SecurityPolicyProtocol
class StaticWebsiteWithExistingSourcesAndSecurityPolicyStack(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")
StaticWebsite(self, "StaticWebsite",
bucket_configuration=WebsiteBucketProps(
source="../path/to/your/static/webpage",
removal_policy=RemovalPolicy.DESTROY
),
alias_configuration=AliasProps(
domain_name="cloudcomponents.org",
names=["www.cloudcomponents.org", "cloudcomponents.org"],
acm_cert_ref=certificate_arn,
security_policy=SecurityPolicyProtocol.TLS_V1_2_2018
)
)
Lambda@Edge function
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
website.add_lambda_function_association(
function_arn="arn:aws:lambda:...",
function_version="1",
event_type="origin-request"
)
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-static-website-1.0.61.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe29ceefe55ca55cf6a03871e9162942e432b8e68fc87fd6ed4dcdb806301ab5 |
|
MD5 | eaccbf590273bb31f7fefec2e488dd6f |
|
BLAKE2b-256 | c6b749f325645dbe075a6eb577ea3c546e4389458e0e85cde693dd904efb127f |
Close
Hashes for cloudcomponents.cdk_static_website-1.0.61-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db0c711870e35aeb8204f8349dafa07c8a0084c7a8a0afb12b2ed7d151ddd489 |
|
MD5 | ca48d06cb3962dafa9a5317c5ceff354 |
|
BLAKE2b-256 | f9a9e5d3172dc81fb1a14eedc6d6aebb59bf4b8064d33941cc612449fccd9cb3 |