Deploy Analog on AWS
Deploy your Analog applications to AWS using Thunder patterns. This guide covers both static site generation (SSG) deployment and full-stack server-side rendering (SSR) options.
There are two deployment patterns available for Analog on AWS:
- Static Site Generation (SSG) — Deploy static Analog sites using S3 and CloudFront with the Single Page Application pattern
- Full Stack — Deploy SSR Analog applications using ECS Fargate with the Web Service pattern
Static Site Generation (SSG) Deployment
Deploy client-side Analog applications to S3 and CloudFront using the CDK-SPA library. This pattern is ideal for static sites, blogs, and client-side applications.
Create Project
npm create analog my-analog-appcd my-analog-apppnpm create analog my-analog-appcd my-analog-appbun create analog my-analog-appcd my-analog-appConfigure Analog for SSG
For details, refer to Analog SSG documentation.
import { defineConfig } from 'vite';import analog from '@analogjs/platform';
// https://vitejs.dev/config/export default defineConfig(({ mode }) => ({ plugins: [ analog({ static: true }), ],}));Install Dependencies and Setup Stack
npm i tsx @thunderso/cdk-spa --save-devpnpm add -D tsx @thunderso/cdk-spabun add -d tsx @thunderso/cdk-spaimport { Cdk, SPAStack, type SPAProps } from "@thunderso/cdk-spa";
const myApp: SPAProps = { env: { account: 'your-account-id', region: 'us-east-1' }, application: 'your-application-id', service: 'your-service-id', environment: 'production',
rootDir: '', // e.g. 'frontend/' for monorepos outputDir: 'dist/',};
new SPAStack( new Cdk.App(), `${myApp.application}-${myApp.service}-${myApp.environment}-stack`, myApp);Environment Variables and Secrets for Build
Configure build-time environment variables using the buildProps configuration:
const myApp: SPAProps = { // ... other props
buildProps: { environment: [ { VITE_API_URL: 'https://api.example.com' }, { VITE_ANALYTICS_ID: 'UA-XXXXXX' } ], secrets: [ { key: 'API_KEY', resource: '/my-app/API_KEY' }, ], },};Deploy
Build and deploy your SPA:
npm run buildnpx cdk deploy --all --app="npx tsx stack/index.ts"pnpm run buildpnpm exec cdk deploy --all --app="pnpm exec tsx stack/index.ts"bun run buildnpx cdk deploy --all --app="bunx tsx stack/index.ts"After deployment, you’ll receive a CloudFront URL to access your application.
For complete documentation, see the CDK-SPA README.
Full Stack Deployment
Deploy server-side rendered Analog applications using ECS Fargate and Application Load Balancer with the CDK-WebService library.
Configure Analog for SSR
Analog enables SSR by default. Refer to Analog SSR documentation.
Install Dependencies and Setup Stack
npm i tsx @thunderso/cdk-webservice --save-devpnpm add -D tsx @thunderso/cdk-webservicebun add -d tsx @thunderso/cdk-webserviceimport { Cdk, WebServiceStack, type WebServiceProps } from "@thunderso/cdk-webservice";
const svcProps: WebServiceProps = { env: { account: 'your-account-id', region: 'us-west-2' }, application: 'your-application-id', service: 'your-service-id', environment: 'production',
rootDir: '', // e.g. 'app/' for monorepos};
new WebServiceStack( new Cdk.App(), `${svcProps.application}-${svcProps.service}-${svcProps.environment}-stack`, svcProps);Build Settings Using Nixpacks
Configure automatic containerization with Nixpacks:
const svcProps: WebServiceProps = { // ... other props
buildProps: { buildSystem: 'Nixpacks', installcmd: 'bun install', buildcmd: 'bun run build', startcmd: 'bun start', },};Build Settings Using Docker Container
Alternatively, use a custom Dockerfile:
FROM public.ecr.aws/docker/library/alpine
# Install BunRUN curl -fsSL https://bun.sh/install | bash
# Update PATH for bunENV PATH="/root/.bun/bin:$PATH"
# Copy code, install and buildWORKDIR /appCOPY . .RUN bun installRUN bun run build
EXPOSE 5173CMD ["bun", "start"]const svcProps: WebServiceProps = { // ... other props
serviceProps: { dockerFile: 'Dockerfile', port: 5173, },};Environment Variables and Secrets for SSR
Configure runtime environment variables and secrets:
const svcProps: WebServiceProps = { // ... other props
serviceProps: { variables: [ { NODE_ENV: 'production' }, { PUBLIC_API_URL: 'https://api.example.com' } ], secrets: [ { key: 'DATABASE_URL', resource: 'arn:aws:secretsmanager:us-west-2:123456789012:secret:/my-app/DATABASE_URL-abc123' }, ], },};Deploy
Build and deploy your containerized application:
npm run buildnpx cdk deploy --all --app="npx tsx stack/index.ts"pnpm run buildpnpm exec cdk deploy --all --app="pnpm exec tsx stack/index.ts"bun run buildnpx cdk deploy --all --app="bunx tsx stack/index.ts"After deployment, you’ll receive an Application Load Balancer URL to access your SSR application.
For complete documentation, see the CDK-WebService README.