Claude Code के साथ AWS Deployments कैसे Automate करें [Practical Guide]
Claude Code के साथ AWS Deployments कैसे Automate करें [Practical Guide]। Code examples के साथ practical guide।
Claude Code से AWS Deployments Automate क्यों करें
AWS पर deploy करने में configuration files लिखना, IAM roles manage करना, environment variables set करना, और अन्य error-prone tasks शामिल हैं। Claude Code infrastructure code generate करने से deployment execute करने तक सब कुछ assist कर सकता है, आपकी project structure को समझते हुए।
AWS CDK Project Build करना
Claude Code से CDK use करके infrastructure build करने का example।
> AWS CDK से ECS Fargate stack बनाओ।
> App Node.js है जिसके सामने ALB है।
> SSM Parameter Store से environment variables pull करने के लिए configure करो।
Claude Code द्वारा generate किया गया CDK code देखते हैं।
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
Claude Code से Terraform का उपयोग करके भी infrastructure management streamline किया जा सकता है।
> terraform/main.tf में S3 + CloudFront static site hosting define करो।
> Rate limiting के साथ WAF भी set up करो।
> terraform plan output check करके बताओ कि कोई 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
CI/CD pipeline setup भी Claude Code से request किया जा सकता है।
> GitHub Actions workflow बनाओ।
> Main branch पर push होने पर automatically CDK deploy run हो।
> AWS से connect करने के लिए OIDC authentication use करो।
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
Deployment Troubleshooting
Deployment errors आने पर Claude Code से analysis भी request किया जा सकता है।
> cdk deploy से following error आया। Cause और fix बताओ:
> Error: The security group 'sg-xxx' does not exist
Claude Code error message को आपकी project structure के साथ cross-reference करके VPC या security group configuration issues identify करता है। General troubleshooting workflows के लिए Claude Code Productivity को 3x करने वाले 10 Tips देखें।
Deployment Automation के Best Practices
- Environment configs separate करें:
cdk.jsonमेंcontextसे environments switch करें - Drift detection: Regularly
cdk diffrun करके discrepancies check करें - Rollback strategy: Advance में Blue/Green deployment configurations prepare करें
इन settings को CLAUDE.md में document करने से Claude Code हमेशा आपकी project guidelines के aligned code generate करेगा। CLAUDE.md usage के बारे में Complete CLAUDE.md Guide देखें।
Summary
Claude Code से AWS infrastructure setup से CI/CD pipeline configuration तक पूरा deployment workflow streamline किया जा सकता है। CDK, Terraform, और SAM सभी के साथ काम करता है। छोटे stack से शुरू करें और gradually automation expand करें।
Claude Code के बारे में Anthropic Official Documentation देखें। AWS best practices के लिए AWS Well-Architected Framework देखें।
Related Posts
Claude Code से अपने Side Projects को Supercharge कैसे करें [Examples के साथ]
Claude Code से personal development projects को dramatically speed up करना सीखें। Real-world examples और idea से deployment तक practical workflow शामिल है।
Claude Code से Refactoring कैसे Automate करें
Claude Code से efficiently code refactoring automate करना सीखें। Real-world projects के लिए practical prompts और concrete refactoring patterns शामिल हैं।
Claude Code के साथ Complete CORS Configuration Guide
Claude Code का उपयोग करके complete CORS configuration guide सीखें। Practical tips और code examples शामिल हैं।