Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@arc-iac/tf-cdk-spa

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arc-iac/tf-cdk-spa

Easily deploy your Single-Page Application to Amazon Web Services (AWS) S3 and CloudFront using the Cloud Development Kit for Terraform (CDKTF) with TypeScript. This package streamlines the process by utilizing the Cloud Development Kit (CDK) to define AW

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-71.43%
Maintainers
2
Weekly downloads
 
Created
Source

AWS SPA Deployment with CDKTF

Easily deploy your Single-Page Application to Amazon Web Services (AWS) S3 and CloudFront using the Cloud Development Kit for Terraform (CDKTF) with TypeScript. This package streamlines the process by utilizing the Cloud Development Kit (CDK) to define AWS resources.

Prerequisites

Before you begin, ensure you have the following prerequisites in place:

  • AWS Account: You'll need an AWS account to deploy infrastructure and access necessary services.
  • Node.js and npm: Install Node.js and npm (Node Package Manager) on your local development machine.
  • Terraform: Install the Terraform CLI on your local development machine.
  • AWS CLI: Install the AWS CLI and configure it with your AWS credentials.
  • Hosted Zone in Route 53: Set up a hosted zone in AWS Route 53 for your custom domain.

Installation

npm install @arc-iac/tf-cdk-spa

Environment Variables

The deployment process relies on several environment variables. Create a .env file in the project's root directory and set the following variables:

Environment VariableDefault ValueDescription
AWS_REGIONus-east-1AWS region for deployment
AWS_PROFILEdefaultAWS profile for authentication and authorization
S3_BUCKET_NAMEN/AS3 bucket name for storing SPA files
CUSTOM_DOMAINN/ACustom domain for the SPA
HOSTED_ZONE_IDN/ARoute 53 hosted zone ID for the custom domain
RELATIVE_PATH_TO_BUILD_DIR../buildRelative path to the SPA build directory

If any variables are not provided, the default values mentioned above will be used.

Usage

The following example demonstrates how to deploy an SPA using this package:

  1. Install the package using npm install @arc-iac/tf-cdk-spa.
  2. Create a main.ts file.
  3. Add the following TypeScript code:
import { CloudFrontStaticWebsiteStack } from "@arc-iac/tf-cdk-spa";
import { App } from "cdktf";

const app = new App();
new CloudFrontStaticWebsiteStack(app, "spa-host"); // You can change the stack name ("spa-host") as needed.
app.synth();
  1. Configure the Environment variables in .env.
  2. Deploy the infrastructure:
npx cdktf deploy spa-host

This command leverages Terraform and CDK to create AWS resources based on the code in main.ts. The deployment might take a few minutes.

Note: If you have multiple stacks or custom stack names, use cdktf deploy <stack-name>.

  1. Verify the deployment:

After successful deployment, access your SPA through the custom domain specified in CUSTOM_DOMAIN. Keep in mind that CloudFront might take some time to fully activate. If you encounter an AccessDenied error, it's likely due to ongoing CloudFront provisioning. Wait about 15-20 minutes before accessing your resources.

Cleanup

To remove deployed resources from AWS, run:

npx cdktf destroy spa-host

Use this command to destroy infrastructure created during deployment. Confirm the destruction when prompted. Replace spa-host with your stack names if customized.

License

This code is licensed under the MPL-2.0 license.

References

Keywords

FAQs

Package last updated on 30 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc