# AWS CLI configured with credentials
aws configure
# → Access Key, Secret Key, Region: us-east-1
# JWT secret in SSM Parameter Store
aws ssm put-parameter --name "/pedidos/jwt-secret" --type SecureString --value "YOUR_SECRET"# One-time build + watch for changes (~5s per code change)
sam sync --stack-name pedidos-backend-dev --watch
# Or traditional deploy (1-3 min)
sam build && sam deploysam sync --watch monitors file changes and:
- Code changes (e.g., edit
app.py): uploads directly to Lambda viaUpdateFunctionCodeAPI (~5s, bypasses CloudFormation) - Infrastructure changes (e.g., add a route): triggers a full CloudFormation deploy (~1-3 min)
sam build
sam deploy --config-env staging
# → Reviews changeset → Confirm (y/n) → Deploysam build
sam deploy --config-env prod
# → Reviews changeset → Confirm (y/n) → Canary deploymentProduction deploys use Canary10Percent5Minutes:
- 10% of traffic goes to the new version
- Waits 5 minutes
- If no alarms trigger → shifts 100% to new version
- If CloudWatch alarm fires (≥5 Lambda errors/min) → automatic rollback
The ApiErrorAlarm CloudWatch alarm monitors Lambda errors across all functions. During a canary deployment, if ≥5 errors occur in 1 minute, CodeDeploy automatically rolls back to the previous Lambda version.
# Roll back the entire stack to the previous deployment
aws cloudformation rollback-stack --stack-name pedidos-backend-prodEach Lambda has a live alias pointing to an immutable version. To roll back a specific function:
# List recent versions
aws lambda list-versions-by-function --function-name pedidos-backend-prod-AuthFunction
# Point alias to previous version
aws lambda update-alias \
--function-name pedidos-backend-prod-AuthFunction \
--name live \
--function-version PREVIOUS_VERSION_NUMBERThis is instant (no CloudFormation involved).
# Build
sam build
# Interactive guided deploy (creates S3 bucket, sets parameters)
sam deploy --guided
# Or use samconfig.toml defaults
sam deploy # → dev
sam deploy --config-env staging # → staging
sam deploy --config-env prod # → prod| Aspect | sam sync |
sam deploy |
|---|---|---|
| Speed (code change) | ~5 seconds | 1-3 minutes |
| Speed (infra change) | 1-3 minutes | 1-3 minutes |
| Uses CloudFormation | Only for infra | Always |
| Changeset review | No | Yes (if confirm_changeset = true) |
| Best for | Development | Staging / Production |
| Watch mode | --watch flag |
N/A |
# Check stack status
aws cloudformation describe-stacks --stack-name pedidos-backend-dev
# Tail Lambda logs
sam logs -n AuthFunction --stack-name pedidos-backend-dev --tail
# View stack outputs (API URL, table name)
sam list stack-outputs --stack-name pedidos-backend-dev
# Delete a stack entirely
sam delete --stack-name pedidos-backend-devAfter building the backend infrastructure, deploy the frontend to the S3+CloudFront stack:
# Build (reads VITE_API_URL from .env.production)
cd pedidos-front
npm run build
# Upload to S3 (--delete removes stale files)
aws s3 sync dist s3://pedidos-frontend-dev-561047280243 --delete --profile pedidos-dev
# Invalidate CloudFront cache
aws cloudfront create-invalidation --distribution-id E1OCCKUDA2YJ14 --paths "/*" --profile pedidos-dev| Resource | Value |
|---|---|
| API URL | https://l4kdt7tpc3.execute-api.us-east-1.amazonaws.com/dev/api/ |
| CloudFront URL | https://d1rjfebhaffmeo.cloudfront.net |
| S3 Bucket | pedidos-frontend-dev-561047280243 |
| CloudFront ID | E1OCCKUDA2YJ14 |
| DynamoDB Table | PedidosTable-dev |
| AWS Account | 561047280243 (pedidos-dev) |
| AWS Profile | pedidos-dev |
| Region | us-east-1 |