Skip to main content
skill CX Codex

aws-cloudformation-ec2 — Claude Code skill: how it works

aws-cloudformation-ec2 generates production-grade AWS CloudFormation templates for EC2 virtual servers, security groups, IAM instance profiles, and load balancers.

MIT ★ 372 updated 2026-09-10

Install into Claude Code · Plugin marketplace All methods and platforms ↓
/plugin marketplace add giuseppe-trisciuoglio/developer-kit
/plugin install developer-kit-aws@developer-kit
Open on GitHub

What aws-cloudformation-ec2 does

The skill provides structural patterns for provisioning compute resources with CloudFormation. It covers strongly typed parameters such as AWS::EC2::InstanceType, network rules for Security Groups, least-privilege IAM roles with SSM management access, and target group bindings for Application Load Balancers. Patterns support both On-Demand and SPOT instances.

Included guidelines demonstrate how to inject base64-encoded UserData launch scripts, organise resource tags, and export stack identifiers in the Outputs block for cross-stack references. It also supplies CLI commands to validate templates using aws cloudformation validate-template and deploy changes via change sets.

Executing deployment commands and writing template files directly to disk relies on the Read, Write, and Bash tools in Claude Code alongside an active AWS CLI setup.

What it helps with

  • generate CloudFormation templates for EC2 compute instances and launch scripts
  • set up Security Group ingress rules for web and administrative traffic
  • configure least-privilege IAM roles and instance profiles for SSM access
  • attach Application Load Balancers with HTTP listeners and target health checks
  • export stack outputs to enable cross-stack template imports

Example prompts for the agent

  • Draft a CloudFormation template running an EC2 instance with an SSM instance profile and HTTP access
  • Create an Application Load Balancer setup with two public subnets and a health check target group
  • Add cross-stack exports for the instance ID and load balancer DNS name to my template

How to install aws-cloudformation-ec2

1Plugin marketplace

/plugin marketplace add giuseppe-trisciuoglio/developer-kit
/plugin install developer-kit-aws@developer-kit

This installs the whole developer-kit-aws plugin with all its skills

2Skills CLI (Vercel)

npx skills add giuseppe-trisciuoglio/developer-kit --skill aws-cloudformation-ec2 -a claude-code

3Manually: put the files in place

~/.claude/skills/aws-cloudformation-ec2/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/aws-cloudformation-ec2/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about aws-cloudformation-ec2

How to install aws-cloudformation-ec2 in Claude Code?

Run /plugin marketplace add giuseppe-trisciuoglio/developer-kit followed by /plugin install developer-kit-aws@developer-kit. Alternatively, use npx skills add giuseppe-trisciuoglio/developer-kit --skill aws-cloudformation-ec2 -a claude-code.

What does aws-cloudformation-ec2 do?

It guides the agent through building structured CloudFormation stacks for EC2 virtual machines, ALB networking, IAM roles, and change set workflows.

What tools are needed to use this skill?

The skill requires Read, Write, and Bash permissions to inspect files, write YAML templates, and run template validation commands.

Source text

SKILL.md · MIT
---
name: aws-cloudformation-ec2
description: Provides AWS CloudFormation patterns for EC2 instances, Security Groups, IAM roles, and load balancers. Use when creating EC2 instances, SPOT instances, Security Groups, IAM roles for EC2, Application Load Balancers (ALB), Target Groups, and implementing template structure with Parameters, Outputs, Mappings, Conditions, and cross-stack references.
allowed-tools: Read, Write, Bash
---

# AWS CloudFormation EC2 Infrastructure

## Overview

Create production-ready EC2 infrastructure using AWS CloudFormation templates. Covers EC2 instances (On-Demand and SPOT), Security Groups, IAM roles, Application Load Balancers (ALB), template structure, parameters, outputs, and cross-stack references.

## When to Use

- Creating EC2 instances (On-Demand or SPOT) with Security Groups and IAM roles
- Setting up Application Load Balancers with target groups
- Implementing template Parameters, Mappings, Conditions, and cross-stack references

## Instructions

### Step 1 — Define Template Parameters

Use AWS-specific parameter types for validation and console dropdowns.

```yaml
Parameters:
  LatestAmiId:
    Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
    Default: /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2

  InstanceType:
    Type: AWS::EC2::InstanceType
    Default: t3.micro
    AllowedValues: [t3.micro, t3.small, t3.medium]

  KeyName:
    Type: AWS::EC2::KeyPair::KeyName
```

See [template-structure.md](references/template-structure.md) for advanced parameter patterns, mappings, conditions, and cross-stack references.

### Step 2 — Create Security Group

Define ingress/egress rules for network access.

```yaml
InstanceSecurityGroup:
  Type: AWS::EC2::SecurityGroup
  Properties:
    GroupDescription: Security group for EC2 instance
    VpcId: !Ref VpcId
    SecurityGroupIngress:
      - IpProtocol: tcp
        FromPort: 80
        ToPort: 80
        CidrIp: 0.0.0.0/0
      - IpProtocol: tcp
        FromPort: 22
        ToPort: 22
        CidrIp: 10.0.0.0/16
```

See [security-iam.md](references/security-iam.md) for advanced security group patterns, self-references, and IAM roles.

### Step 3 — Configure IAM Role

Define instance profile with least privilege permissions.

```yaml
Ec2Role:
  Type: AWS::IAM::Role
  Properties:
    AssumeRolePolicyDocument:
      Version: "2012-10-17"
      Statement:
        - Effect: Allow
          Principal:
            Service: ec2.amazonaws.com
          Action: sts:AssumeRole
    ManagedPolicyArns:
      - arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore

Ec2InstanceProfile:
  Type: AWS::IAM::InstanceProfile
  Properties:
    Roles: [!Ref Ec2Role]
```

See [security-iam.md](references/security-iam.md) for least privilege policies, SSM roles, and trust policies.

### Step 4 — Launch EC2 Instance

Configure instance with security group, IAM role, and user data.

```yaml
Ec2Instance:
  Type: AWS::EC2::Instance
  Properties:
    ImageId: !Ref LatestAmiId
    InstanceType: !Ref InstanceType
    KeyName: !Ref KeyName
    SecurityGroupIds: [!Ref InstanceSecurityGroup]
    IamInstanceProfile: !Ref Ec2InstanceProfile
    SubnetId: !Ref SubnetId
    UserData:
      Fn::Base64: |
        #!/bin/bash
        yum update -y
        yum install -y httpd
        systemctl start httpd
    Tags:
      - Key: Name
        Value: !Sub ${AWS::StackName}-instance
```

See [ec2-instances.md](references/ec2-instances.md) for multi-volume configurations, detailed monitoring, SPOT instances, and complete stack examples.

**Validate template:** `aws cloudformation validate-template --template-body file://template.yaml`

### Step 5 — Add Application Load Balancer

Create ALB with target group and listener for traffic distribution.

```yaml
ApplicationLoadBalancer:
  Type: AWS::ElasticLoadBalancingV2::LoadBalancer
  Properties:
    Name: !Sub ${AWS::StackName}-alb
    Scheme: internet-facing
    SecurityGroups: [!Ref AlbSecurityGroup]
    Subnets: [!Ref PublicSubnet1, !Ref PublicSubnet2]

ApplicationTargetGroup:
  Type: AWS::ElasticLoadBalancingV2::TargetGroup
  Properties:
    Port: 80
    Protocol: HTTP
    VpcId: !Ref VpcId
    HealthCheckPath: /health

ApplicationListener:
  Type: AWS::ElasticLoadBalancingV2::Listener
  Properties:
    DefaultActions:
      - Type: forward
        TargetGroupArn: !Ref ApplicationTargetGroup
    LoadBalancerArn: !Ref ApplicationLoadBalancer
    Port: 80
    Protocol: HTTP
```

See [load-balancers.md](references/load-balancers.md) for HTTPS configuration, path-based routing, host-based routing, listener rules, and ALB attributes.

### Step 6 — Define Outputs

Export values for cross-stack references.

```yaml
Outputs:
  InstanceId:
    Description: EC2 Instance ID
    Value: !Ref Ec2Instance
    Export:
      Name: !Sub ${AWS::StackName}-InstanceId

  SecurityGroupId:
    Description: Security Group ID
    Value: !Ref InstanceSecurityGroup
    Export:
      Name: !Sub ${AWS::StackName}-SecurityGroupId

  LoadBalancerDnsName:
    Description: ALB DNS Name
    Value: !GetAtt ApplicationLoadBalancer.DNSName
```

See [template-structure.md](references/template-structure.md) for cross-stack reference patterns and import/export strategies.

## Examples

### Minimal EC2 with ALB Template

```yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: EC2 instance with ALB

Parameters:
  LatestAmiId:
    Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
    Default: /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2
  InstanceType:
    Type: AWS::EC2::InstanceType
    Default: t3.micro

Resources:
  InstanceSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Enable HTTP and SSH
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 80
          ToPort: 80
          CidrIp: 0.0.0.0/0

  Ec2Instance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: !Ref LatestAmiId
      InstanceType: !Ref InstanceType
      SecurityGroupIds: [!Ref InstanceSecurityGroup]

  LoadBalancer:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      Scheme: internet-facing
      SecurityGroups: [!Ref InstanceSecurityGroup]
      Subnets: [subnet-12345678, subnet-87654321]

Outputs:
  InstanceId:
    Value: !Ref Ec2Instance
  LoadBalancerDns:
    Value: !GetAtt LoadBalancer.DNSName
```

### Deploy with Change Set

```bash
# Create change set
aws cloudformation create-change-set \
  --stack-name my-ec2-stack \
  --template-body file://template.yaml \
  --change-set-type CREATE

# Execute after review
aws cloudformation execute-change-set \
  --change-set-name <change-set-name>
```

See [examples.md](references/examples.md) for complete production-ready templates.

## Best Practices

### Template Structure
- **Use AWS-specific parameter types** for validation (`AWS::EC2::VPC::Id`, `AWS::EC2::InstanceType`)
- **Organize by lifecycle** - separate network, security, and application stacks
- **Use meaningful names** with `AWS::StackName` prefix
- **Enable termination protection** on production stacks

### Security
- **Apply least privilege** to IAM roles - grant minimum required permissions
- **Use security group references** instead of IP addresses where possible
- **Enable IMDSv2** on all EC2 instances
- **Restrict security group rules** to specific CIDR blocks

### Cost & Availability
- **Use SPOT instances** for fault-tolerant, interruptible workloads
- **Deploy across multiple AZs** for high availability
- **Set up CloudWatch alarms** for CPU and status checks
- **Use EBS gp3 volumes** for cost-effective storage

### Operations
- **Always use change sets** for production stack updates
- **Enable drift detection** to maintain template compliance
- **Apply stack policies** to protect critical resources
- **Validate templates** before deployment with `aws cloudformation validate-template`

See [best-practices.md](references/best-practices.md) for detailed guidance on stack policies, termination protection, drift detection, change set automation, and validation scripts.

## References

### Core Configuration
- **[template-structure.md](references/template-structure.md)** — Template sections, parameters, mappings, conditions, outputs, cross-stack references
- **[ec2-instances.md](references/ec2-instances.md)** — EC2 instances, SPOT fleets, multi-volume configurations, complete stack examples
- **[security-iam.md](references/security-iam.md)** — Security groups, IAM roles, instance profiles, least privilege policies
- **[load-balancers.md](references/load-balancers.md)** — ALB configuration, target groups, listeners, path-based routing, HTTPS

### Operational Guides
- **[best-practices.md](references/best-practices.md)** — Stack policies, termination protection, drift detection, change sets, validation
- **[constraints.md](references/constraints.md)** — Resource limits, instance constraints, cost considerations, common issues, monitoring

### Additional Resources
- **[examples.md](references/examples.md)** — Complete production-ready examples and use cases
- **[reference.md](references/reference.md)** — CloudFormation EC2 resource reference documentation

## Constraints and Warnings

### Resource Limits
- Maximum 500 resources per CloudFormation stack
- Maximum 500 security groups per VPC
- Instance types vary by region/A availability

### Cost Considerations
- EC2 instances incur costs while running
- EBS volumes charged per GB-month even when not attached
- ALBs have hourly + LCU data processing costs
- Unattached Elastic IPs incur hourly costs

### Security Considerations
- Key pairs cannot be recovered if lost
- Instance profile roles cannot be changed after creation
- IMDSv1 has security vulnerabilities - use IMDSv2
- Spot instances can be terminated with 2-minute notice

See [constraints.md](references/constraints.md) for complete constraints, troubleshooting guides, and monitoring setup.

© Giuseppe Trisciuoglio · MIT · giuseppe-trisciuoglio/developer-kit

Similar skills

All skills for Cloud: AWS, Azure, GCP →

From the same set191

The whole set →
spring-boot-code-review-expert spring-boot-code-review-expert reads a Spring Boot diff and checks it against Java and Spring conventions. Returns findings ranked by severity, each with a code sample. CX Codex ★ 372repo stars general-code-explorer general-code-explorer traces feature implementations across codebases, maps call flows from entry points to data layers, and documents architectural patterns. CX Codex ★ 372repo stars devkit.generate-security-assessment The devkit.generate-security-assessment command turns project structure and audit findings into a structured security assessment. Use it after an audit when you need a report in a chosen language and format. CX Codex +1 ★ 372repo stars lambda-conventions lambda-conventions establishes directory structure, file naming, and validation patterns for AWS Lambda functions built with NestJS and deployed via SAM. Keeps handler implementations and configs consistent across a team. CX Codex +1 ★ 372repo stars devkit.java.refactor-class devkit.java.refactor-class — a Claude Code command that inspects a Java class and rewrites it following Clean Architecture, DDD, and Spring Boot patterns. Takes a file path, a refactoring scope, and optional flags like dry-run or backup. CX Codex +1 ★ 372repo stars general-debugger general-debugger takes a crash or a failing test down to the line that caused it: reads the stack trace, walks the execution path backwards, then suggests a small fix. CX Codex ★ 372repo stars document-generator-expert document-generator-expert generates technical assessments, feature specs, process docs, and analysis reports directly from your codebase. CX Codex ★ 372repo stars spring-boot-unit-testing-expert The spring-boot-unit-testing-expert subagent plans and writes Spring Boot unit tests with JUnit 5, Mockito, and Spring Test. Call it when adding coverage or reviewing test design. CX Codex ★ 372repo stars

Project sponsors

Companies that keep this analytics open