This commit is contained in:
Toby
2026-01-27 17:35:45 -05:00
commit 2639af6531
176 changed files with 27104 additions and 0 deletions
+81
View File
@@ -0,0 +1,81 @@
---
name: aws-ec2
description: Manage EC2 instances, AMIs, and auto-scaling groups. Configure security groups, key pairs, and instance types. Use when deploying compute resources on AWS.
license: MIT
metadata:
author: devops-skills
version: "1.0"
---
# AWS EC2
Deploy and manage Amazon EC2 compute instances.
## Launch Instance
```bash
aws ec2 run-instances \
--image-id ami-0abcdef1234567890 \
--instance-type t3.micro \
--key-name my-key \
--security-group-ids sg-12345678 \
--subnet-id subnet-12345678 \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=web-server}]'
```
## Auto Scaling
```bash
# Create launch template
aws ec2 create-launch-template \
--launch-template-name web-template \
--version-description v1 \
--launch-template-data '{
"ImageId": "ami-xxx",
"InstanceType": "t3.micro"
}'
# Create ASG
aws autoscaling create-auto-scaling-group \
--auto-scaling-group-name web-asg \
--launch-template LaunchTemplateName=web-template \
--min-size 2 --max-size 10 --desired-capacity 2 \
--vpc-zone-identifier "subnet-xxx,subnet-yyy"
```
## User Data
```bash
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
```
## Instance Management
```bash
# List instances
aws ec2 describe-instances --filters "Name=tag:Name,Values=web*"
# Stop/Start
aws ec2 stop-instances --instance-ids i-xxx
aws ec2 start-instances --instance-ids i-xxx
# Create AMI
aws ec2 create-image --instance-id i-xxx --name "my-ami"
```
## Best Practices
- Use launch templates
- Implement auto-scaling
- Use spot instances for cost savings
- Regular AMI updates
- Instance metadata service v2
## Related Skills
- [terraform-aws](../terraform-aws/) - IaC deployment
- [aws-vpc](../aws-vpc/) - Networking
@@ -0,0 +1,98 @@
# EC2 Operations Reference
## Instance Management
```bash
# Launch instance
aws ec2 run-instances \
--image-id ami-12345678 \
--instance-type t3.micro \
--key-name mykey \
--security-group-ids sg-12345678 \
--subnet-id subnet-12345678
# Start/Stop/Terminate
aws ec2 start-instances --instance-ids i-12345678
aws ec2 stop-instances --instance-ids i-12345678
aws ec2 terminate-instances --instance-ids i-12345678
# Describe instances
aws ec2 describe-instances \
--filters "Name=tag:Environment,Values=prod"
```
## AMI Management
```bash
# Create AMI from instance
aws ec2 create-image \
--instance-id i-12345678 \
--name "MyApp-$(date +%Y%m%d)"
# Copy AMI to another region
aws ec2 copy-image \
--source-image-id ami-12345678 \
--source-region us-east-1 \
--region us-west-2 \
--name "MyApp-copy"
```
## Instance Types
| Type | vCPU | Memory | Use Case |
|------|------|--------|----------|
| t3.micro | 2 | 1 GB | Dev/Test |
| t3.small | 2 | 2 GB | Light apps |
| m5.large | 2 | 8 GB | General |
| c5.large | 2 | 4 GB | Compute |
| r5.large | 2 | 16 GB | Memory |
## User Data
```bash
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "Hello World" > /var/www/html/index.html
```
## Instance Metadata
```bash
# IMDSv2
TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/
# Common endpoints
/latest/meta-data/instance-id
/latest/meta-data/local-ipv4
/latest/meta-data/public-ipv4
/latest/meta-data/iam/security-credentials/role-name
```
## Terraform
```hcl
resource "aws_instance" "app" {
ami = data.aws_ami.amazon_linux.id
instance_type = "t3.micro"
vpc_security_group_ids = [aws_security_group.app.id]
subnet_id = aws_subnet.private.id
iam_instance_profile = aws_iam_instance_profile.app.name
user_data = base64encode(file("userdata.sh"))
root_block_device {
volume_size = 20
encrypted = true
}
tags = {
Name = "app-server"
}
}
```