agentleFS
eliecer2000eliecer2000/kiro-bootstrap/skills/aws-ec2/SKILL.md

aws-ec2

Skill9 starsChanged 8 months agoMITView on GitHub

Amazon EC2 instance configuration. Use when setting up AMIs, instance types, security groups, IAM roles, Auto Scaling Groups, EBS volumes or Packer golden images.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

AWS EC2

Skill para configurar instancias EC2: AMIs, instance types, security groups, IAM roles, user data, Auto Scaling Groups, EBS volumes, Packer para golden images y mejores prácticas de seguridad y costos.

Principios fundamentales

  • Serverless-first: usar EC2 solo cuando Lambda/Fargate no cubren el caso de uso (procesos largos, GPU, software con licencia, cargas constantes).
  • IAM roles en lugar de access keys. Nunca hardcodear credenciales en user data.
  • Security groups con least privilege: solo puertos necesarios desde fuentes específicas.
  • SSH restringido a IPs conocidas o usar SSM Session Manager (sin puerto 22 abierto).
  • AMIs versionadas con Packer para deployments reproducibles.

Security group seguro (CDK)

const sg = new ec2.SecurityGroup(this, 'WebSG', {
  vpc,
  description: 'Web server security group',
  allowAllOutbound: true,
});

// Solo HTTPS desde internet
sg.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(443), 'HTTPS');

// SSH solo desde bastion o SSM (preferir SSM)
// sg.addIngressRule(ec2.Peer.ipv4('10.0.0.0/8'), ec2.Port.tcp(22), 'SSH from VPC');

Instancia EC2 con SSM (CDK)

const instance = new ec2.Instance(this, 'WebServer', {
  vpc,
  vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS },
  instanceType: ec2.InstanceType.of(ec2.InstanceClass.T4G, ec2.InstanceSize.MICRO),
  machineImage: ec2.MachineImage.latestAmazonLinux2023({
    cpuType: ec2.AmazonLinuxCpuType.ARM_64,
  }),
  ssmSessionPermissions: true, // SSM Session Manager en lugar de SSH
  blockDevices: [{
    deviceName: '/dev/xvda',
    volume: ec2.BlockDeviceVolume.ebs(20, {
      encrypted: true,
      volumeType: ec2.EbsDeviceVolumeType.GP3,
    }),
  }],
});

Auto Scaling Group (CDK)

const asg = new autoscaling.AutoScalingGroup(this, 'ASG', {
  vpc,
  instanceType: ec2.InstanceType.of(ec2.InstanceClass.T4G, ec2.InstanceSize.SMALL),
  machineImage: ec2.MachineImage.latestAmazonLinux2023(),
  minCapacity: 2,
  maxCapacity: 10,
  healthCheck: autoscaling.HealthCheck.elb({ grace: cdk.Duration.minutes(5) }),
});

asg.scaleOnCpuUtilization('CpuScaling', {
  targetUtilizationPercent: 70,
  cooldown: cdk.Duration.minutes(5),
});

Golden images con Packer

packer {
  required_plugins {
    amazon = {
      source  = "github.com/hashicorp/amazon"
      version = "~> 1.3"
    }
  }
}

locals {
  timestamp = regex_replace(timestamp(), "[- TZ:]", "")
}

source "amazon-ebs" "app" {
  region        = var.region
  instance_type = "t3.micro"

  source_ami_filter {
    filters = {
      name                = "al2023-ami-*-x86_64"
      root-device-type    = "ebs"
      virtualization-type = "hvm"
    }
    most_recent = true
    owners      = ["amazon"]
  }

  ssh_username = "ec2-user"
  ami_name     = "my-app-${local.timestamp}"

  tags = {
    Name      = "my-app"
    BuildDate = local.timestamp
    ManagedBy = "Packer"
  }
}

build {
  sources = ["source.amazon-ebs.app"]

  provisioner "shell" {
    inline = [
      "sudo dnf update -y",
      "sudo dnf install -y nodejs20 nginx",
    ]
  }
}

Comandos Packer

packer init .
packer validate .
packer build .
packer build -var "region=us-east-1" .

Cuándo usar EC2 vs Lambda vs Fargate

CriterioLambdaFargateEC2
Duración< 15 minIlimitadaIlimitada
RAM máxima10 GB120 GBIlimitada
GPUNoNoSí
Cold startSíSí (menor)No
Costo variablePay-per-invocationPay-per-vCPU/horaPay-per-hora
Caso idealEvent-driven, APIsContainers, microservicesCargas constantes, GPU, licencias

Anti-patrones a evitar

  • ❌ SSH abierto a 0.0.0.0/0.
  • ❌ Access keys hardcodeadas en user data.
  • ❌ Instancias sin IAM role (usando access keys en su lugar).
  • ❌ EBS volumes sin cifrado.
  • ❌ AMIs desactualizadas sin parches de seguridad.
  • ❌ Over-provisioning sin medir uso real.
  • ❌ Instancias on-demand para cargas estables (usar Savings Plans).
  • ❌ No usar Auto Scaling para cargas variables.
  • ❌ Termination protection deshabilitada en producción.
  • ❌ Usar EC2 cuando Lambda o Fargate cubren el caso de uso.

Checklist de revisión EC2

  • Security groups con least privilege (no 0.0.0.0/0 en SSH).
  • IAM role asignado (no access keys).
  • SSM Session Manager habilitado (preferir sobre SSH).
  • EBS volumes cifrados.
  • AMI versionada con Packer o similar.
  • Auto Scaling configurado para cargas variables.
  • CloudWatch monitoring habilitado.
  • Termination protection en producción.
  • Savings Plans evaluados para cargas estables.
  • Subnet privada con NAT Gateway (no pública salvo ALB).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.