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 deployIncremental 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 --forceEnvironment-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 prodEnvironment 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-cacheState 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 --allResource 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-distributionBest 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.json3. 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-profileCI/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_KEYDeployment Options Summary
| Option | Description |
|---|---|
--env <name> | Environment name |
--config <path> | Config file path |
--profile <name> | AWS profile |
--dry-run | Preview mode |
--force | Full redeployment |
--no-cloudfront | Skip CloudFront |
--skip-cache | Skip cache invalidation |
--skip-build | Skip automatic build |
Next Steps
- API Reference - CLI commands reference
- Configuration - Configuration options reference
- Troubleshooting - Fix deployment issues