Automated management for AWS EC2 instances and infrastructure lifecycle.

Install

mkdir -p .claude/skills/ec2 && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/3106" && unzip -o skill.zip -d .claude/skills/ec2 && rm skill.zip

Installs to .claude/skills/ec2

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

AWS EC2 virtual machine management for instances, AMIs, and networking. Use when launching instances, configuring security groups, managing key pairs, troubleshooting connectivity, or automating instance lifecycle.
214 chars · catalog description✓ has a “when” trigger
Intermediate

Key capabilities

  • Provision EC2 instances with custom configurations
  • Manage security group ingress and egress rules
  • Automate instance lifecycle via Auto Scaling Groups
  • Troubleshoot connectivity using Session Manager
  • Create and manage AMIs and EBS snapshots

How it works

It interacts with the AWS EC2 API to manage virtual machine lifecycles, networking, and security configurations through CLI commands or Python scripts.

Inputs & outputs

You give it
Instance specifications and AWS resource parameters
You get back
Provisioned EC2 infrastructure or diagnostic report

When to use ec2

  • Provision new EC2 instances
  • Configure security group rules
  • Troubleshoot SSH connection issues
  • Manage EBS volume snapshots
  • Set up Auto Scaling groups

About this skill

AWS EC2

Amazon Elastic Compute Cloud (EC2) provides resizable compute capacity in the cloud.

Advanced patterns (Auto Scaling, Spot Fleets, Session Manager, Instance Connect, IMDS, Placement Groups, scheduled scaling): see instance-management.md.

Table of Contents

Core Concepts

Instance Types

CategoryExampleUse Case
General Purposet3, m6i, t4g (Graviton)Web servers, dev environments
Compute Optimizedc6i, c7g (Graviton)Batch processing, gaming
Memory Optimizedr6i, r7g (Graviton)Databases, caching
Storage Optimizedi3, d3Data warehousing
Acceleratedp4d, g5ML, graphics

Graviton (ARM) instances (t4g, m7g, c7g, r7g) are ~20% cheaper than x86 equivalents for the same performance — worth considering for new workloads.

Purchasing Options

OptionDescription
On-DemandPay by the hour/second
Reserved1-3 year commitment, up to 72% discount
SpotUnused capacity, up to 90% discount — can be interrupted with 2-minute notice
Savings PlansFlexible commitment-based discount

AMI (Amazon Machine Image)

Template containing OS, software, and configuration for launching instances. Use SSM Parameter Store to look up the latest official AMIs rather than hardcoding IDs:

# Latest Amazon Linux 2 AMI
aws ssm get-parameter \
  --name /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2 \
  --query 'Parameter.Value' --output text

# Latest Amazon Linux 2023
aws ssm get-parameter \
  --name /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64 \
  --query 'Parameter.Value' --output text

# Latest Ubuntu 22.04
aws ssm get-parameter \
  --name /aws/service/canonical/ubuntu/server/22.04/stable/current/amd64/hvm/ebs-gp2/ami-id \
  --query 'Parameter.Value' --output text

Security Groups

Virtual firewalls controlling inbound and outbound traffic. Changes take effect immediately — no restart required.

Common Patterns

Launch an Instance

# Create key pair
aws ec2 create-key-pair \
  --key-name my-key \
  --query 'KeyMaterial' \
  --output text > my-key.pem
chmod 400 my-key.pem

# Create security group
aws ec2 create-security-group \
  --group-name web-server-sg \
  --description "Web server security group" \
  --vpc-id vpc-12345678

# Allow SSH and HTTP
aws ec2 authorize-security-group-ingress \
  --group-id sg-12345678 \
  --protocol tcp \
  --port 22 \
  --cidr 10.0.0.0/8

aws ec2 authorize-security-group-ingress \
  --group-id sg-12345678 \
  --protocol tcp \
  --port 80 \
  --cidr 0.0.0.0/0

# Launch instance
aws ec2 run-instances \
  --image-id ami-0123456789abcdef0 \
  --instance-type t3.micro \
  --key-name my-key \
  --security-group-ids sg-12345678 \
  --subnet-id subnet-12345678 \
  --associate-public-ip-address \
  --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=web-server}]'

# Wait until running, then get IP
aws ec2 wait instance-running --instance-ids i-1234567890abcdef0
aws ec2 describe-instances \
  --instance-ids i-1234567890abcdef0 \
  --query 'Reservations[].Instances[].PublicIpAddress' --output text

boto3:

import boto3

ec2 = boto3.resource('ec2')

instances = ec2.create_instances(
    ImageId='ami-0123456789abcdef0',
    InstanceType='t3.micro',
    KeyName='my-key',
    SecurityGroupIds=['sg-12345678'],
    SubnetId='subnet-12345678',
    MinCount=1,
    MaxCount=1,
    TagSpecifications=[{
        'ResourceType': 'instance',
        'Tags': [{'Key': 'Name', 'Value': 'web-server'}]
    }]
)

instance = instances[0]
instance.wait_until_running()
instance.reload()
print(f"Instance ID: {instance.id}")
print(f"Public IP: {instance.public_ip_address}")

User Data Script

OS package manager note:

  • Amazon Linux 2: use amazon-linux-extras install nginx1 -yyum install nginx fails because nginx is not in the default AL2 repos
  • Amazon Linux 2023: use dnf install -y nginx
  • Ubuntu: use apt-get install -y nginx
  • Amazon Linux 2 / RHEL: httpd (Apache) is always available via yum install -y httpd
# Amazon Linux 2 — nginx via amazon-linux-extras
aws ec2 run-instances \
  --image-id ami-0123456789abcdef0 \
  --instance-type t3.micro \
  --key-name my-key \
  --security-group-ids sg-12345678 \
  --subnet-id subnet-12345678 \
  --user-data '#!/bin/bash
amazon-linux-extras install nginx1 -y
systemctl start nginx
systemctl enable nginx
'

# Amazon Linux 2 — httpd (Apache, simpler alternative)
# --user-data '#!/bin/bash
# yum install -y httpd
# systemctl start httpd
# systemctl enable httpd
# echo "<h1>Hello from $(hostname -f)</h1>" > /var/www/html/index.html
# '

Attach IAM Role

# Create instance profile
aws iam create-instance-profile \
  --instance-profile-name web-server-profile

aws iam add-role-to-instance-profile \
  --instance-profile-name web-server-profile \
  --role-name web-server-role

# Launch with profile
aws ec2 run-instances \
  --image-id ami-0123456789abcdef0 \
  --instance-type t3.micro \
  --iam-instance-profile Name=web-server-profile \
  ...

Create AMI from Instance

aws ec2 create-image \
  --instance-id i-1234567890abcdef0 \
  --name "my-custom-ami-$(date +%Y%m%d)" \
  --description "Custom AMI with web server" \
  --no-reboot

Auto Scaling Group with Spot (Modern Approach)

The recommended way to use Spot Instances at scale is via Auto Scaling Groups with a mixed-instances policy — not the legacy request-spot-instances API. This supports instance diversification to minimize interruptions.

See instance-management.md for the full setup. Quick example:

# 1. Create launch template with IMDSv2
aws ec2 create-launch-template \
  --launch-template-name my-lt \
  --launch-template-data '{
    "ImageId": "ami-0123456789abcdef0",
    "SecurityGroupIds": ["sg-12345678"],
    "IamInstanceProfile": {"Name": "my-profile"},
    "MetadataOptions": {"HttpTokens": "required", "HttpEndpoint": "enabled"}
  }'

# 2. Create ASG with mixed-instances (Spot + On-Demand diversification)
aws autoscaling create-auto-scaling-group \
  --auto-scaling-group-name my-asg \
  --min-size 0 --max-size 20 --desired-capacity 2 \
  --vpc-zone-identifier "subnet-111,subnet-222" \
  --mixed-instances-policy '{
    "LaunchTemplate": {
      "LaunchTemplateSpecification": {"LaunchTemplateName": "my-lt", "Version": "$Latest"},
      "Overrides": [
        {"InstanceType": "c5.xlarge"},
        {"InstanceType": "c5.2xlarge"},
        {"InstanceType": "c5a.xlarge"}
      ]
    },
    "InstancesDistribution": {
      "OnDemandBaseCapacity": 0,
      "OnDemandPercentageAboveBaseCapacity": 0,
      "SpotAllocationStrategy": "capacity-optimized"
    }
  }'

EBS Volume Management

# Create volume
aws ec2 create-volume \
  --availability-zone us-east-1a \
  --size 100 \
  --volume-type gp3 \
  --iops 3000 \
  --throughput 125 \
  --encrypted

# Attach to instance
aws ec2 attach-volume \
  --volume-id vol-12345678 \
  --instance-id i-1234567890abcdef0 \
  --device /dev/sdf

# Create snapshot
aws ec2 create-snapshot \
  --volume-id vol-12345678 \
  --description "Daily backup"

CLI Reference

Instance Management

CommandDescription
aws ec2 run-instancesLaunch instances
aws ec2 describe-instancesList instances
aws ec2 start-instancesStart stopped instances
aws ec2 stop-instancesStop running instances
aws ec2 reboot-instancesReboot instances
aws ec2 terminate-instancesTerminate instances
aws ec2 modify-instance-attributeModify instance settings

Security Groups

CommandDescription
aws ec2 create-security-groupCreate security group
aws ec2 describe-security-groupsList security groups
aws ec2 authorize-security-group-ingressAdd inbound rule
aws ec2 revoke-security-group-ingressRemove inbound rule
aws ec2 authorize-security-group-egressAdd outbound rule

AMIs

CommandDescription
aws ec2 describe-imagesList AMIs
aws ec2 create-imageCreate AMI from instance
aws ec2 copy-imageCopy AMI to another region
aws ec2 deregister-imageDelete AMI

EBS Volumes

CommandDescription
aws ec2 create-volumeCreate EBS volume
aws ec2 attach-volumeAttach to instance
aws ec2 detach-volumeDetach from instance
aws ec2 create-snapshotCreate snapshot
aws ec2 modify-volumeResize/modify volume

Best Practices

Security

  • Use IAM roles instead of access keys on instances
  • Restrict security groups — principle of least privilege
  • Use private subnets for backend instances
  • Enable IMDSv2 to prevent SSRF attacks
  • Encrypt EBS volumes at rest
# Require IMDSv2 on existing instance
aws ec2 modify-instance-metadata-options \
  --instance-id i-1234567890abcdef0 \
  --http-tokens required \
  --http-endpoint enabled

Performance

  • Right-size instances — monitor and adjust
  • Use EBS-optimized instances
  • Choose appropriate EBS volume type (gp3 is the default good choice; io2 for high IOPS)
  • Use placement groups for low-latency networking (see instance-management.md)

Cost Optimization

  • Use Spot Instances for fault-tolerant workloads (batch, ML training, CI)
  • Stop/terminate unused instances
  • Use Reserved Instances or Savings Plans for steady-state workloads
  • Delete unused EBS volumes and snapshots
  • **Consider Graviton (t4g, m7g, c

Content truncated.

When not to use it

  • Managing non-AWS compute resources

Prerequisites

AWS CLIboto3

Limitations

  • Limited by AWS service availability and account quotas
  • Requires proper IAM permissions for all operations

How it compares

It provides a structured approach to infrastructure management compared to manual console clicks, ensuring repeatable and automated deployments.

Compared to similar skills

ec2 side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
ec2 (this skill)13moReviewIntermediate
aws-solution-architect203moReviewAdvanced
terraform-module-library74moNo flagsAdvanced
cloud-architect63moNo flagsAdvanced

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

aws-solution-architect

alirezarezvani

Design AWS architectures for startups using serverless patterns and IaC templates. Use when asked to design serverless architecture, create CloudFormation templates, optimize AWS costs, set up CI/CD pipelines, or migrate to AWS. Covers Lambda, API Gateway, DynamoDB, ECS, Aurora, and cost optimization.

2047

terraform-module-library

wshobson

Build reusable Terraform modules for AWS, Azure, and GCP infrastructure following infrastructure-as-code best practices. Use when creating infrastructure modules, standardizing cloud provisioning, or implementing reusable IaC components.

759

cloud-architect

sickn33

Expert cloud architect specializing in AWS/Azure/GCP multi-cloud infrastructure design, advanced IaC (Terraform/OpenTofu/CDK), FinOps cost optimization, and modern architectural patterns. Masters serverless, microservices, security, compliance, and disaster recovery. Use PROACTIVELY for cloud architecture, cost optimization, migration planning, or multi-cloud strategies.

649

kubernetes-architect

sickn33

Expert Kubernetes architect specializing in cloud-native infrastructure, advanced GitOps workflows (ArgoCD/Flux), and enterprise container orchestration. Masters EKS/AKS/GKE, service mesh (Istio/Linkerd), progressive delivery, multi-tenancy, and platform engineering. Handles security, observability, cost optimization, and developer experience. Use PROACTIVELY for K8s architecture, GitOps implementation, or cloud-native platform design.

636

aws-advisor

tech-leads-club

Expert AWS Cloud Advisor for architecture design, security review, and implementation guidance. Leverages AWS MCP tools for accurate, documentation-backed answers. Use when user asks about AWS architecture, security, service selection, migrations, troubleshooting, or learning AWS. Triggers on AWS, Lambda, S3, EC2, ECS, EKS, DynamoDB, RDS, CloudFormation, CDK, Terraform, Serverless, SAM, IAM, VPC, API Gateway, or any AWS service.

529

devops-iac-engineer

davila7

Implements infrastructure as code using Terraform, Kubernetes, and cloud platforms. Designs scalable architectures, CI/CD pipelines, and observability solutions. Provides security-first DevOps practices and site reliability engineering guidance.

223

Search skills

Search the agent skills registry