Noncommital Premarital Mischief

    @c3l/static-cdn
    TypeScript icon, indicating that this package has built-in type declarations

    1.3.0 • Public • Published

    C3L: CDN-fronted S3 bucket for serving static content

    This is a basic CDK construct for delivering static web content through a CDN.

    Please refer to general C3L documentation here.

    Install this package:

    npm i @c3l/static-cdn

    The following shows a sample usage:

    import cdk = require('@aws-cdk/cdk');
    import { StaticCDN } from '../lib/static-cdn';
    
    export class TestStack extends cdk.Stack {
      constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
        super(scope, id, props);
    
        new StaticCDN(this, 'TestCDN', {
          domain: 'test.hello-world.sh',
          zone: 'Z2S9HZFROM1LZW',
          zoneName: 'hello-world.sh.',
          certificate: 'arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012'
        })
      }
    }

    If you don't have a matching ACM certificate in us-east-1, you can create one like this:

    import acm = require('@aws-cdk/aws-certificatemanager');
    import cdk = require('@aws-cdk/cdk');
    import { CfnOutput } from '@aws-cdk/cdk';
    import { HostedZone } from '@aws-cdk/aws-route53';
    
    export class CertStack extends cdk.Stack {
      constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
        super(scope, id, props);
    
        const certificate = new acm.DnsValidatedCertificate(this, 'Certificate', {
          domainName: '*.hello-world.sh',
          hostedZone: HostedZone.fromHostedZoneAttributes(this, 'Zone', {
            hostedZoneId: 'Z2S9HZFROM1LZW',
            zoneName: 'hello-world.sh.'
          })
        });
        new CfnOutput(this, 'CertificateARN', {
          value: certificate.certificateArn
        })
      }
    }

    Regardless of where you'd like to deploy your origin bucket (TestStack), your certificate needs to be in us-east-1. You can instruct your CDK app to deploy the CertStack in the mother region and deploy the rest to you local default. Here is how to do that:

    import cdk = require('@aws-cdk/cdk');
    import { CertStack } from './cert-stack';
    import { TestStack } from './test-stack';
    
    const app = new cdk.App();
    new CertStack(app, 'CertStack', { env: { region: 'us-east-1'} });
    new TestStack(app, 'TestStack');
    app.run();

    Keywords

    none

    Install

    npm i @c3l/static-cdn

    DownloadsWeekly Downloads

    1

    Version

    1.3.0

    License

    ISC

    Unpacked Size

    18.6 kB

    Total Files

    10

    Last publish

    Collaborators

    • helloworlddan