robisson/build-like-amazon-agent-skills/infrastructure-as-code
Claude Code and agent skill by robisson/build-like-amazon-agent-skills
- community
Checking that the SKILL.md file is still in the repository.
CDK/CloudFormation design principles for immutable infrastructure, environment parity, least privilege, tagging strategy, and cost optimization. Infrastructure is code—it deserves the same rigor as application code.
Install
npx vskill@latest install robisson/build-like-amazon-agent-skills/infrastructure-as-codeSKILL.md
The same SKILL.md was published earlier as robisson/build-like-amazon-agent-skills/infrastructure-as-code.
Infrastructure as Code
Overview
Infrastructure as Code (IaC) means every piece of infrastructure—compute, storage, networking, permissions, monitoring—is defined in version-controlled code that can be reviewed, tested, and deployed through the same pipeline as application code. There is no "clicking in the console." There are no snowflake environments. The code IS the infrastructure, and the infrastructure IS the code.
Immutable infrastructure means you never patch in place. You replace. A server is never SSH'd into and modified; it is destroyed and rebuilt from the code. This eliminates configuration drift, makes deployments predictable, and ensures every environment is reproducible.
When to Use
- Always. All infrastructure must be defined in code. There are no exceptions.
- When creating a new service or microservice
- When modifying any infrastructure component (networking, IAM, storage, compute)
- When setting up a new environment (dev, staging, production)
- When responding to an incident that requires infrastructure changes
- When optimizing costs (changes must be in code so they're reproducible and reviewable)
Amazon Context
At Amazon, teams own their infrastructure end-to-end. There is no separate "ops team" that provisions resources. The team that builds the service provisions, deploys, monitors, and operates the infrastructure. CDK (Cloud Development Kit) and CloudFormation are the primary tools, with CDK preferred for new projects because it provides type safety, composition, and testing capabilities that raw CloudFormation templates lack.
Infrastructure changes go through the same code review and deployment pipeline as application code. A CDK change that modifies IAM permissions gets the same scrutiny as a code change that handles authentication. In many ways, it deserves MORE scrutiny—a bad IAM policy can expose the entire account.
The Process
1. Immutable Infrastructure
Principles
- Never modify running infrastructure. To change a server's configuration, create a new server with the new configuration and destroy the old one.
- No SSH in production. If you need to SSH in, your automation is incomplete. Fix the automation.
- Identical artifacts across environments. The same AMI/container image deployed to dev is deployed to production. Only configuration (env vars, secrets references) differs.
- Rebuild from scratch regularly. If you can't destroy and recreate your entire environment from code in under an hour, your IaC is incomplete.
Implementation
2. Environment Parity
The Rule
Production, staging, and development environments must be structurally identical. They differ only in:
- Scale (instance count, storage size)
- Configuration values (endpoints, account IDs)
- Data (production has real data; lower environments have synthetic data)
They must NOT differ in:
- Architecture (same services, same topology)
- Security posture (same IAM structure, same encryption)
- Networking model (same VPC design, same security groups)
- Monitoring (same metrics, same alarms—different thresholds are acceptable)
Implementation
3. Least Privilege
IAM Design Principles
- Start with zero permissions. Add only what's needed, one permission at a time.
- Scope to specific resources. Never use
Resource: "*"unless there is no alternative. - Use conditions. Restrict by source IP, time, MFA, tags, or organization.
- Prefer managed policies for AWS services. Custom policies for application-specific access.
- Separate read and write roles. A service that reads from DynamoDB and writes to S3 should have separate role assumptions if possible.
- Time-bound elevated access. Admin access should be temporary (STS assume-role with session duration).
Common Violations and Fixes
IAM Review Checklist
- [ ] No
Action: "*"(wildcard actions) - [ ] No
Resource: "*"without documented justification - [ ] No inline policies on IAM users (use roles)
- [ ] Cross-account access uses external ID condition
- [ ] Service roles have trust policy scoped to specific service principal
- [ ] Admin access requires MFA and has session time limit
- [ ] Permissions boundaries are applied to delegated admin roles
4. Tagging Strategy
Mandatory Tags
Every resource must have these tags (enforced by Service Control Policy):
| Tag Key | Description | Example Values | |
|---|---|---|---|
service | Service name (matches repo name) | payment-processing | |
environment | Deployment environment | dev, staging, production | |
team | Owning team name | payments-core | |
cost-center | Finance cost allocation code | CC-12345 | |
data-classification | Data sensitivity level | public, internal, confidential, restricted | |
managed-by | IaC tool managing this resource | cdk, cloudformation, terraform |
Enforcement
Tag-Based Policies
- Cost allocation: All cost reports filter by
serviceandteamtags - Access control: IAM policies use
aws:ResourceTagconditions - Automation: Auto-shutdown of dev resources uses
environment: devtag - Compliance: Audit queries use
data-classificationtag to verify encryption
5. Cost Optimization
Design-Time Cost Decisions
| Decision | Cost Impact | Guideline | |
|---|---|---|---|
| Instance type | 40-60% of compute cost | Right-size based on actual metrics, not guesses. Start small, scale up. | |
| Storage class | 20-50% of storage cost | Use lifecycle policies: hot → warm → cold → archive | |
| Reserved vs. On-Demand | 30-60% savings | Reserve steady-state baseline; On-Demand for burst | |
| Region selection | 10-30% variation | Use cheapest region that meets latency requirements | |
| Data transfer | Often overlooked | Keep data in same AZ/region where possible; use VPC endpoints |
Cost Guardrails in Code
Cost Monitoring
- Budget alarms: Set per-service monthly budget with alerts at 50%, 80%, 100%
- Anomaly detection: AWS Cost Anomaly Detection enabled per-service tag
- Weekly review: Automated cost report per team, compared to previous week
- Unused resource detection: Automated scan for unattached EBS, idle EC2, empty S3 buckets
6. CDK Best Practices
Project Structure
Testing Infrastructure Code
Construct Composition
- L1 (Cfn): Raw CloudFormation. Use only when L2 doesn't exist.
- L2: AWS-opinionated defaults. Use as building blocks.
- L3 (Custom): Your team's opinionated constructs. Encode your standards.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/infrastructure-as-code/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/robisson/build-like-amazon-agent-skills/infrastructure-as-code)