| name | dsg-infrastructure-deployer |
| version | 1.0.0 |
| author | DSG Team |
| license | MIT |
| description | Deploy and manage DSG ONE / ProofGate control plane infrastructure on AWS using CDK. Automate the complete deployment pipeline: CloudFormation stack creation, resource validation, Secrets Manager inte |
DSG Infrastructure Deployer
Automated deployment and lifecycle management of DSG ONE / ProofGate Control Plane infrastructure on AWS.
When to invoke this skill
| Intent | Use this skill |
|---|
| "Deploy DSG to AWS dev/staging/production" | ✅ Yes — full CDK deployment pipeline |
| "Verify AWS infrastructure is healthy" | ✅ Yes — health checks and diagnostics |
| "Check deployment status and resource count" | ✅ Yes — CloudFormation status monitoring |
| "Document AWS resource outputs" | ✅ Yes — automated capture and templating |
| "Troubleshoot CloudFormation deployment failure" | ✅ Yes — error diagnosis and recovery |
| "Update infrastructure configuration" | ✅ Yes — CDK synth and targeted updates |
| "Set up production AWS accounts" | ✅ Yes — account setup and IAM configuration |
| "Build a generic AWS app (not DSG)" | ❌ Out of scope — use AWS CDK docs directly |
Core deployment workflow
Phase 1: Pre-deployment validation
1. CHECK ENVIRONMENT
✓ AWS credentials available (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
✓ AWS region configured (AWS_REGION, default: us-east-1)
✓ AWS account ID known (AWS_ACCOUNT_ID)
✓ CDK CLI available (npm exec cdk)
✓ Node.js and npm installed
2. VALIDATE CONFIGURATION
✓ Environment type specified (dev, staging, prod)
✓ Stack name follows convention: dsg-one-{env}-v2
✓ No conflicting CloudFormation stacks
✓ Supabase connection configured (if database required)
✓ Docker registry configured (if ECR push needed)
3. REVIEW CONSTRUCTS
✓ Networking (VPC, subnets, NAT, security groups)
✓ ECS (cluster, Fargate task definition, service)
✓ ALB (load balancer, listeners, target groups)
✓ Database (DynamoDB tables)
✓ Storage (S3 buckets for evidence, CloudTrail logs)
✓ Security (KMS encryption keys, Secrets Manager)
✓ Monitoring (CloudWatch logs, X-Ray)
✓ Audit (CloudTrail, VPC Flow Logs)
Phase 2: Synth and dry-run
cd infra/cdk
npx cdk synth --require-approval=never
Phase 3: Deploy infrastructure
cd infra/cdk
npx cdk deploy --require-approval=never
Phase 4: Post-deployment verification
1. VERIFY CLOUDFORMATION
✓ Stack status: CREATE_COMPLETE or UPDATE_COMPLETE
✓ Resource count: 75 resources created
✓ No DELETE_FAILED or CREATE_FAILED resources
✓ Stack outputs available (ALB DNS, RDS endpoint, etc.)
2. HEALTH CHECKS
✓ curl GET /api/health → 200 OK
✓ curl GET /api/readiness → ready: true
✓ curl GET /api/agent/status → deployment info
✓ AWS ECS service running desired task count
✓ ALB health checks passing (target group healthy)
✓ RDS database accepting connections
✓ Secrets Manager secrets accessible
3. RESOURCE VALIDATION
✓ VPC CIDR: 10.0.0.0/16 (configurable)
✓ Subnets: 2 public + 2 private (multi-AZ)
✓ NAT Gateway: 1 per AZ (for private egress)
✓ ECS cluster: Running tasks = desired count
✓ ALB: Listening on :80 and :443
✓ DynamoDB tables: 3 tables (policies, audit, replay-proofs)
✓ S3 buckets: Evidence bucket + CloudTrail bucket + CDK bucket
✓ KMS keys: Master key + data key, rotation enabled
✓ Secrets: api-secrets, database-secrets, oauth-secrets
4. SECURITY VERIFICATION
✓ All data encrypted at rest (KMS)
✓ All data encrypted in transit (TLS)
✓ IAM roles follow least-privilege principle
✓ RLS policies on Supabase tables (if using)
✓ VPC endpoints for private service access
✓ Security groups restrict traffic to required ports
✓ CloudTrail logging enabled
✓ CloudWatch Logs retention configured
5. COMPLIANCE READINESS
✓ Audit trail tables created (DynamoDB)
✓ Evidence bucket configured (S3)
✓ Compliance matrix seeded
✓ CCVS pipeline ready for evidence collection
Configuration by environment
Development (dev)
{
environment: "dev",
vpcCidr: "10.0.0.0/16",
ecsDesiredCount: 1,
ecsTaskMemory: 512,
rdsInstanceClass: "t3.micro",
enableAutoScaling: false,
enableCloudTrail: true,
cloudWatchRetention: 7,
backupRetention: 7,
tags: { Environment: "dev", ManagedBy: "CDK" }
}
Staging
{
environment: "staging",
vpcCidr: "10.0.0.0/16",
ecsDesiredCount: 2,
ecsTaskMemory: 1024,
rdsInstanceClass: "t3.small",
enableAutoScaling: true,
enableCloudTrail: true,
cloudWatchRetention: 30,
backupRetention: 30,
tags: { Environment: "staging", ManagedBy: "CDK" }
}
Production (prod)
{
environment: "prod",
vpcCidr: "10.0.0.0/16",
ecsDesiredCount: 3,
ecsTaskMemory: 2048,
rdsInstanceClass: "t3.large",
enableAutoScaling: true,
enableCloudTrail: true,
enableVPCFlowLogs: true,
cloudWatchRetention: 365,
backupRetention: 90,
enableMultiAZ: true,
enableBackupVault: true,
tags: { Environment: "prod", ManagedBy: "CDK", CostCenter: "Engineering" }
}
Stack naming and versioning
DSG uses a versioned stack naming convention to avoid CloudFormation conflicts:
Pattern: dsg-one-{environment}-v{number}
Examples:
dsg-one-dev-v1 (old, may be stuck in DELETE_FAILED)
dsg-one-dev-v2 (current)
dsg-one-dev-v3 (next version if v2 conflicts)
dsg-one-staging-v1
dsg-one-prod-v1
Why versioning?
- CloudFormation can get stuck in
DELETE_FAILED if the old stack can't clean up resources
- Incrementing version allows immediate redeployment without waiting
- Old stacks can be manually cleaned up later
- Resource naming also uses
-v{N} suffix (e.g., dsg-policy-table-v2)
Common deployment scenarios
Scenario 1: Fresh deployment to dev
echo $AWS_REGION
echo $AWS_ACCOUNT_ID
cd infra/cdk && npx cdk synth --require-approval=never
npx cdk deploy --require-approval=never
curl https://<ALB_DNS>/api/health
npm run go:no-go https://<ALB_DNS>
Scenario 2: Update existing infrastructure
cd infra/cdk && npx cdk synth --require-approval=never
npx cdk deploy DSGOneStack-dev --require-approval=never
curl https://<ALB_DNS>/api/agent/status
Scenario 3: Troubleshoot deployment failure
aws cloudformation describe-stacks --stack-name dsg-one-dev-v2 --region us-east-1
aws cloudformation describe-stack-resources \
--stack-name dsg-one-dev-v2 \
--query 'StackResources[?ResourceStatus==`CREATE_FAILED`]' \
--region us-east-1
cd infra/cdk && npx cdk synth --require-approval=never
npm run typecheck
Post-deployment tasks
1. Capture infrastructure outputs
./scripts/capture-aws-outputs.sh \
--stack-name dsg-one-dev-v2 \
--region us-east-1 \
--environment dev
2. Build and deploy application
npm run build
docker build -t dsg-control-plane:latest .
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com
docker tag dsg-control-plane:latest <ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/dsg-api:latest
docker push <ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/dsg-api:latest
aws ecs update-service \
--cluster dsg-one-dev-v2 \
--service dsg-service \
--force-new-deployment
3. Configure DNS and TLS
aws route53 change-resource-record-sets \
--hosted-zone-id <ZONE_ID> \
--change-batch file://route53-change.json
4. Set up monitoring and alerts
aws cloudwatch put-metric-alarm \
--alarm-name dsg-alb-unhealthy-targets \
--alarm-description "Alert if ALB has unhealthy targets" \
--metric-name UnHealthyHostCount \
--namespace AWS/ApplicationELB \
--statistic Sum \
--period 300 \
--threshold 1 \
--comparison-operator GreaterThanOrEqualToThreshold
aws sns subscribe \
--topic-arn <SNS_TOPIC> \
--protocol email \
--notification-endpoint ops@dsg.pics
Troubleshooting
CloudFormation stack stuck in UPDATE_IN_PROGRESS
Cause: Previous CDK deploy didn't complete or is still running
Solution:
ps aux | grep cdk
aws cloudformation describe-stack-events \
--stack-name dsg-one-dev-v2 \
--query 'StackEvents[0:10]' \
--region us-east-1
ALB target group reports "Unhealthy"
Cause: ECS task is crashing or not responding to health checks
Solution:
aws ecs describe-tasks \
--cluster dsg-one-dev-v2 \
--tasks <TASK_ARN> \
--region us-east-1
aws logs tail /ecs/dsg-control-plane --follow
S3 bucket deletion failed
Cause: CloudFormation tries to delete non-empty S3 buckets
Solution:
aws s3 rm s3://dsg-cloudtrail-bucket-<account> --recursive
aws s3 rm s3://dsg-evidence-bucket-<account> --recursive
// removalPolicy: cdk.RemovalPolicy.DESTROY,
// → removalPolicy: cdk.RemovalPolicy.RETAIN,
aws cloudformation delete-stack --stack-name dsg-one-dev-v2
DynamoDB table naming conflicts
Cause: Table names like dsg-policy-table already exist from previous deployment
Solution:
// tableName: 'dsg-policy-table-v2',
// CDK auto-generates unique names without explicit tableName
npx cdk deploy --require-approval=never
Deployment success criteria
✅ Deployment is ready when:
✅ Production readiness when:
Next steps
- Complete CDK deployment (wait 30-45 minutes for initial stack)
- Verify infrastructure health (run health checks and diagnostics)
- Capture AWS outputs (document resources created)
- Build and deploy application (Docker → ECR → ECS)
- Configure DNS and TLS (Route53 + ACM)
- Set up monitoring (CloudWatch alarms, SNS)
- Run production readiness validator (compliance checks)
- Document runbooks (deployment, scaling, recovery procedures)
- Schedule runbook reviews (monthly for prod)