Giter Club home page Giter Club logo

cdk-webapp-tools's Introduction

cdk-webapp-config

A collection of CDK constructs to assist in working with single-page web applications deployed on AWS.

Constructs

This library current includes the following constructs:

Construct Name Description
WebAppConfig This construct enables you to deploy a config file that can be read at runtime for values that won't be available at synth time for your CDK app. This commonly includes values like API endpoint and user pool id.
WebAppDeployment This construct enables you to build web applications and deploy them to an S3 bucket. You can configure many aspects of this process, and it should work for most modern single-page web applications.

You can review the docs for this construct library for configuration examples.

Examples

WebAppConfig

CDK Construct that enables you to deploy a custom configuration file to an S3 bucket for your single-page web app.

Documentation

Example

new WebAppConfig(this, 'ReactAppConfig', {
  bucket: appBucket,
  key: 'config.js',
  configData: {
    userPoolId: appPool.userPoolId,
    userPoolClientId: appClient.userPoolClientId,
    apiEndpoint: appHttpApi.apiEndpoint
  },
  globalVariableName: 'appConfig'
});

This config would result in a file called config.js in your specified bucket that would contain the following contents:

window['appConfig'] = {
  userPoolId: 'xxxxxxxxxxxxxxx',
  userPoolClientId: 'xxxxxxxxxxxxxxx',
  apiEndpoint: 'xxxxxxxxxxxxxx'
};

WebAppDeployment

CDK Construct that enables you to build and deploy a web application to an S3 bucket.

This includes the ability to execute a command that you specify (such as npm build or yarn build) to build your application. If you are on Mac or Linux, it will attempt to run that locally before launching Docker to build.

Documentation

Basic Example

new WebAppDeployment(this, 'WebAppDeploy', {
    webAppDirectory: 'webapp',
    webDistribution: webDistribution,
    webDistributionPaths: ['/*'],
    buildCommand: 'yarn build',
    buildDirectory: 'build',
    bucket: hostingBucket,
    prune: true
  });

Example for hoisted dependencies (monorepo)

new WebAppDeployment(this, 'WebAppDeploy', {
    baseDirectory: '../',
    relativeWebAppPath: 'webapp',
    webDistribution: webDistribution,
    webDistributionPaths: ['/*'],
    buildCommand: 'yarn build',
    buildDirectory: 'build',
    bucket: hostingBucket,
    prune: true
  });

cdk-webapp-tools's People

Contributors

davidtucker avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.