Deployment Guide

Learn how to deploy and manage your static websites effectively with SCF.

Basic Deployment

Deploy your site with a single command:

bash
# Basic deployment (uses scf.config.ts)
npx scf-deploy deploy

Incremental Deployment

SCF performs incremental deployment by default. It compares file hashes and uploads only changed files.

Benefits:

  • Faster deployments
  • Lower S3 costs
  • Reduced bandwidth usage

If you need a full redeployment:

bash
# Force full redeployment
npx scf-deploy deploy --force

Environment-Specific Deployment

Use the --env option for environment-specific settings:

bash
# Development
npx scf-deploy deploy --env dev

# Staging
npx scf-deploy deploy --env staging

# Production
npx scf-deploy deploy --env prod

Environment overrides in config file:

typescript
import { defineConfig } from 'scf-deploy';

export default defineConfig({
  app: 'my-static-site',
  region: 'ap-northeast-2',

  s3: {
    bucketName: 'my-site-dev',
    buildDir: './dist',
  },

  cloudfront: {
    enabled: true,
    priceClass: 'PriceClass_100',
  },

  environments: {
    dev: {
      s3: { bucketName: 'my-site-dev' },
      cloudfront: { enabled: false },
    },
    staging: {
      s3: { bucketName: 'my-site-staging' },
    },
    prod: {
      s3: { bucketName: 'my-site-prod' },
      cloudfront: {
        priceClass: 'PriceClass_All',
        customDomain: {
          domainName: 'www.example.com',
        },
      },
    },
  },
});

Cache Invalidation

CloudFront caches content for performance. SCF automatically invalidates the cache after deployment.

bash
# Default deployment (includes automatic cache invalidation)
npx scf-deploy deploy

# Skip cache invalidation
npx scf-deploy deploy --skip-cache

State Recovery

If you've lost your state file, you can recover it by searching for existing resources in AWS:

bash
# Recover state file
npx scf-deploy recover

# Search all SCF managed resources
npx scf-deploy recover --all

Resource Removal

Remove deployed AWS resources:

bash
# Remove resources (with confirmation)
npx scf-deploy remove

# Force removal without confirmation
npx scf-deploy remove --force

# Keep specific resources
npx scf-deploy remove --keep-bucket
npx scf-deploy remove --keep-distribution

Best Practices

1. Use Version Control

Commit your configuration:

bash
git add scf.config.ts
git commit -m "Add SCF configuration"

2. Ignore State Files

Add to .gitignore:

gitignore
# SCF state files
.deploy/
*.deploy.json

3. Use Environment Variables

Manage sensitive information with environment variables:

bash
# Set environment variables
export AWS_ACCESS_KEY_ID=your-access-key
export AWS_SECRET_ACCESS_KEY=your-secret-key

# Or use AWS profile
npx scf-deploy deploy --profile my-aws-profile

CI/CD Integration

GitHub Actions

yaml
name: Deploy to AWS

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'

      - name: Install dependencies
        run: npm install

      - name: Build
        run: npm run build

      - name: Deploy to AWS
        run: npx scf-deploy deploy --env prod
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

Security: Store AWS credentials in GitHub Secrets.

GitLab CI

yaml
deploy:
  stage: deploy
  image: node:18
  script:
    - npm install
    - npm run build
    - npx scf-deploy deploy --env prod
  only:
    - main
  variables:
    AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
    AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY

Deployment Options Summary

OptionDescription
--env <name>Environment name
--config <path>Config file path
--profile <name>AWS profile
--dry-runPreview mode
--forceFull redeployment
--no-cloudfrontSkip CloudFront
--skip-cacheSkip cache invalidation
--skip-buildSkip automatic build

Next Steps

3 min readLast updated: 2025-11-25