0.1.1 • Published 6 months ago
@hands-on-aws-cdk-book/custom-amplify-construct v0.1.1
Custom Amplify CDK Construct
A simple AWS CDK construct for creating Amplify applications with configurable environment variables.
Installation
npm install @hands-on-aws-cdk-book/custom-amplify-construct
Usage
import { CustomAmplifyConstruct } from "@hands-on-aws-cdk-book/custom-amplify-construct";
// Basic usage
const basicApp = new CustomAmplifyConstruct(this, "BasicApp", {
appName: "MyApp",
githubRepositoryUrl: "https://github.com/username/repo",
githubTokenSecretName: "github-token",
});
// With environment variables
const appWithEnv = new CustomAmplifyConstruct(this, "AppWithEnv", {
appName: "MyApp",
githubRepositoryUrl: "https://github.com/username/repo",
githubTokenSecretName: "github-token",
environmentVariables: {
VITE_API_ENDPOINT: api.url,
VITE_USER_POOL_ID: userPool.userPoolId,
},
});
Prerequisites
- Store your GitHub personal access token in AWS Secrets Manager
- Have a GitHub repository with your Vite application
Environment Variables
All environment variables will be prefixed with VITE_
to work with Vite applications.
The construct automatically adds:
VITE_REGION
: AWS Region
Add any additional environment variables through the environmentVariables
prop.
Build Settings
The construct uses the following build settings:
- Node.js environment
npm ci
for clean installsnpm run build
for production builds- Caches node_modules for faster builds
- Serves from the
build
directory - Handles SPA routing with custom rules
Security
- Uses Secrets Manager for GitHub token
- HTTPS by default
- Environment variables are encrypted at rest