Skip to main content

A custom AWS CDK construct that integrates node for building react projects and deploying them to AWS S3.

Project description

ReactBucketDeployment for AWS CDK

A custom AWS CDK construct that integrates node for building react projects, automating the process of dependency resolution, packaging, and deployment preparation to AWS S3.

Features

  • Automates the build process of React applications using npm.
  • Deploys the built React application to an AWS S3 bucket for hosting.
  • Handles dependency resolution and packaging with npm ci and npm run build.
  • Easily integrates with AWS CDK projects, providing a seamless deployment workflow.

Prerequisites

Installation

To use ReactBucketDeployment in your CDK project, install it via pip:

pip install cdk-react-bucket-deployment

Usage

Here's a basic example of how to use ReactBucketDeployment in your AWS CDK stack:

from aws_cdk import Stack
from aws_cdk.aws_s3 import Bucket
from constructs import Construct
from react_bucket_deployment import ReactBucketDeployment

class MyReactAppStack(Stack):
    def __init__(self, scope: Construct, id: str, **kwargs):
        super().__init__(scope, id, **kwargs)

        bucket = Bucket(self, "MyReactAppBucket")

        ReactBucketDeployment(
            self, "DeployReactApp",
            react_project_path="./path/to/react/project",
            destination_bucket=bucket
        )

Replace ./path/to/react/project with the path to your React project directory.

Configuration

The ReactBucketDeployment construct accepts the following parameters:

  • scope: The scope in which to define this construct (usually self in the context of a stack).
  • id: The scoped construct ID.
  • react_project_path: The file system path to the React project directory.
  • destination_bucket: The S3 bucket instance where the React application will be deployed.

Additional AWS CDK BucketDeployment options can be passed through **kwargs to customize the deployment behavior further.

Local Development

This project uses Poetry for dependency management and packaging, and it's recommended to use Poetry to run local development tasks to ensure consistency with the project's dependencies.

Running tests

All the tests are based on pytest so running them boils down to executing one command:

poetry run pytest

Running Pre-commit Hooks

The project uses pre-commit hooks to ensure code quality and formatting standards. To set up pre-commit hooks within the Poetry environment, which ensures that the hooks are run automatically before each commit, execute the following command:

poetry run pre-commit install

This command installs pre-commit hooks as Git pre-commit hooks, so they are automatically executed before you commit changes. It's a convenient way to ensure your changes adhere to the project's standards without needing to manually run checks before each commit.

If you prefer to run pre-commit hooks manually, perhaps to check files before committing, you can use the following command:

poetry run pre-commit run --all-files

This will manually execute all configured pre-commit hooks on all files in the repository. It's useful for performing a one-time check or for scenarios where you haven't set up automatic pre-commit hooks with pre-commit install.

Running Pyright

Pyright is used for static type checking to catch errors early in development. To run Pyright through Poetry, use the following command:

bash

poetry run pyright

This will execute Pyright type checking based on the project's pyrightconfig.json configuration. Running Pyright helps ensure type consistency and can catch common errors.

Contributing

  • Submitting bug reports and feature requests in the Issues section.
  • Opening pull requests with improvements to code or documentation.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Acknowledgments

  • Thanks to the AWS CDK team for providing the framework.
  • Thanks to the Poetry team for simplifying Python package management.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdk_react_bucket_deployment-0.1.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file cdk_react_bucket_deployment-0.1.1.tar.gz.

File metadata

File hashes

Hashes for cdk_react_bucket_deployment-0.1.1.tar.gz
Algorithm Hash digest
SHA256 656714cc4c69daae527a6228fd5ed4e7d634fe5bb3f5c981aedfefacacbee668
MD5 d64f71a3c06f3b48c6a258d5be20f7be
BLAKE2b-256 5797acf8082adad4e31c8f020dfbb0f99e496b6c3f031fb3bab8d9f56f14b2cb

See more details on using hashes here.

File details

Details for the file cdk_react_bucket_deployment-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cdk_react_bucket_deployment-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3317171afd994a7abc29be1e1251d8459f4a1a4666147df94635869e81f24050
MD5 08973d23c7edd2dd0ef3dcd42bbccc52
BLAKE2b-256 6abe3680528fedf275f67c5757b530127dd094c62a60bda79630b3340e57df40

See more details on using hashes here.

Supported by

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