Nebulous Plasma Muffin

    serverless-respat-static-cloudfront

    2.0.0 • Public • Published

    serverless-respat-static-cloudfront

    Resource pattern to setup a Cloudfront distribution for a static site hosted on S3.

    Usage

    This package is intended for use with the serverless-respat plugin. (install/usage info).

    Install:

    npm install --save-dev serverless-respat-static-cloudfront

    Add patterns to the "custom" object in your serverless config file:

    "custom": {
        "serverless-respat": {
            prefix: "${self:service}-${opt:stage}",
            patterns: [
                {
                    pattern: require("serverless-respat-static-cloudfront"),
                    config: {
                        domain: "YOURDOMAIN",
                        region: '${self:provider.region}',
                        use_https: true,
                        default_root_object: "index.html",
                        certificate_arn: 'ACM_CERT_ARN',
                        origins: [
                            {
                                id: "ApiGatewayOrigin",
                                path: "/my-api",
                                domain: {
                                    "Fn::Join": [
                                        "",
                                        [
                                            {
                                                // "ApiGatewayRestApi" is generated by Serverless
                                                "Ref": "ApiGatewayRestApi"
                                            },
                                            ".execute-api.${self:provider.region}.amazonaws.com"
                                        ]
                                    ]
                                },
                                path_pattern: "api/*"
                            }
                        ]
                    }
                }
            ]
        }
    }

    Before this will work, you need to create an S3 bucket with the same name as your domain. A good choice for deploying your static site to the bucket is the serverless-finch plugin.

    You will also need to setup Route53 (or other DNS service) to point to the Cloudfront resource created

    Config options

    • pattern_name (string, default: "StaticCloudfront") - A pattern name included in resource names.

    • use_https (boolean, default: true) - If true, you site will use HTTPS

    • domain (string, REQUIRED) - Your website domain name

    • region (string, REQUIRED) - AWS region

    • default_root_object (string, REQUIRED) - The root file used from your S3 bucket

    • certificate_arn (string, REQUIRED) - The ARN for the ACM certificate to use for HTTPS

    • origins - (array) List of objects defining the origins to include

      • id - (string, REQUIRED) ID to use for the origin
      • path - (string, REQUIRED) The origin path
      • path_pattern - (string, REQUIRED) Pattern to use for the origin
      • domain - (string, REQUIRED) The domain the origin should point to. (An API Gateway, etc.)

    Keywords

    none

    Install

    npm i serverless-respat-static-cloudfront

    DownloadsWeekly Downloads

    1

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    16.9 kB

    Total Files

    10

    Last publish

    Collaborators

    • traviswimer