How to Automate AWS Deployments with Claude Code [실전 가이드]
How to Automate AWS Deployments: Claude Code 활용 [Practical Guide]. 코드 예시가 포함된 실전 가이드입니다.
Why Automate AWS Deployments with Claude Code
Deploying to AWS involves writing configuration files, managing IAM roles, setting environment variables, and other error-prone tasks. Claude Code can assist with everything from generating infrastructure code to executing deployments, all while understanding your project structure.
Building an AWS CDK Project
Here’s an example of asking Claude Code to build infrastructure using CDK.
> Create an ECS Fargate stack using AWS CDK.
> The app is Node.js with an ALB in front.
> Configure it to pull environment variables from SSM Parameter Store.
Let’s look at the CDK code Claude Code generates.
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import * as ssm from 'aws-cdk-lib/aws-ssm';
export class AppStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const vpc = new ec2.Vpc(this, 'AppVpc', { maxAzs: 2 });
const cluster = new ecs.Cluster(this, 'AppCluster', { vpc });
const taskDef = new ecs.FargateTaskDefinition(this, 'TaskDef', {
memoryLimitMiB: 512,
cpu: 256,
});
const dbHost = ssm.StringParameter.valueForStringParameter(
this, '/app/prod/DB_HOST'
);
taskDef.addContainer('app', {
image: ecs.ContainerImage.fromAsset('./'),
portMappings: [{ containerPort: 3000 }],
environment: { DB_HOST: dbHost },
logging: ecs.LogDrivers.awsLogs({ streamPrefix: 'app' }),
});
const service = new ecs.FargateService(this, 'Service', {
cluster,
taskDefinition: taskDef,
desiredCount: 2,
});
const lb = new elbv2.ApplicationLoadBalancer(this, 'ALB', {
vpc,
internetFacing: true,
});
const listener = lb.addListener('Listener', { port: 80 });
listener.addTargets('Target', {
port: 3000,
targets: [service],
healthCheck: { path: '/health' },
});
}
}
Terraform Integration
You can also streamline infrastructure management with Terraform using Claude Code.
> Define S3 + CloudFront static site hosting in terraform/main.tf.
> Also set up WAF with rate limiting.
> Check the terraform plan output and let me know if there are any issues.
resource "aws_s3_bucket" "site" {
bucket = "my-app-static-site"
}
resource "aws_cloudfront_distribution" "cdn" {
origin {
domain_name = aws_s3_bucket.site.bucket_regional_domain_name
origin_id = "s3-origin"
s3_origin_config {
origin_access_identity = aws_cloudfront_origin_access_identity.oai.cloudfront_access_identity_path
}
}
enabled = true
default_root_object = "index.html"
default_cache_behavior {
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "s3-origin"
viewer_protocol_policy = "redirect-to-https"
forwarded_values {
query_string = false
cookies { forward = "none" }
}
}
restrictions {
geo_restriction { restriction_type = "none" }
}
viewer_certificate {
cloudfront_default_certificate = true
}
}
GitHub Actions Integration
You can also ask Claude Code to set up your CI/CD pipeline.
> Create a GitHub Actions workflow.
> It should automatically run CDK deploy on push to the main branch.
> Use OIDC authentication to connect to AWS.
name: Deploy to AWS
on:
push:
branches: [main]
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/deploy-role
aws-region: us-east-1
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npx cdk deploy --require-approval never
Troubleshooting Deployments
When deployment errors occur, you can also ask Claude Code to analyze them.
> I got the following error from cdk deploy. Tell me the cause and how to fix it:
> Error: The security group 'sg-xxx' does not exist
Claude Code cross-references the error message with your project structure to identify VPC or security group configuration issues. For general troubleshooting workflows, refer to 10 Tips to 3x Your Claude Code Productivity.
Best Practices for Deployment Automation
- Separate environment configs: Switch environments using
contextincdk.json - Drift detection: Run
cdk diffregularly to check for discrepancies - Rollback strategy: Prepare Blue/Green deployment configurations in advance
By documenting these settings in CLAUDE.md, Claude Code will always generate code aligned with your project’s guidelines. For more on CLAUDE.md usage, see the Complete CLAUDE.md Guide.
정리
With Claude Code, you can streamline the entire deployment workflow — from AWS infrastructure setup to CI/CD pipeline configuration. It works with CDK, Terraform, and SAM alike. Start with a small stack and gradually expand your automation.
For more on Claude Code, see the official Anthropic documentation. For AWS best practices, refer to the AWS Well-Architected Framework.
무료 PDF: 5분 완성 Claude Code 치트시트
이메일 주소만 등록하시면 A4 한 장짜리 치트시트 PDF를 즉시 보내드립니다.
개인정보는 엄격하게 관리하며 스팸은 보내지 않습니다.
이 글을 작성한 사람
Masa
Claude Code를 적극 활용하는 엔지니어. 10개 언어, 2,000페이지 이상의 테크 미디어 claudecode-lab.com을 운영 중.
관련 글
Claude Code 다국어 글을 매일 발행하기 전에 확인할 7가지
누락된 언어, 깨진 CTA, 반영되지 않은 배포를 막기 위해 다국어 Claude Code 글을 매일 발행하기 전에 확인할 체크리스트입니다.
Codex Automations란? 잠자는 동안 AI가 콘텐츠 운영을 처리하게 하는 방법
Codex Automations로 트래픽 분석, 주제 선정, 글 작성, CTA 개선, 배포까지 자동화하는 실전 가이드.
Claude Code × GCP Cloud Functions 완전 가이드 | 서버리스 함수 초고속 개발
Claude Code로 GCP Cloud Functions를 효율화. HTTP/Pub/Sub/Firestore 트리거 구현부터 로컬 테스트·배포 자동화까지, Masa의 실무 경험을 토대로 실제 코드로 해설.