AgentSkillsCN

aws-cli-ec2

在使用AWS EC2与Auto Scaling命令时——ECS基础设施的实例、VPC、子网、安全组、密钥对、AMIs、启动模板、自动扩展组。在为ECS容器实例启动或管理EC2实例、创建VPC网络(VPC、子网、互联网网关、NAT网关、路由表)、为ECS流量配置安全组、寻找ECS优化的AMIs、为ECS自动扩展创建启动模板,或管理ECS容量提供商的自动扩展组时使用此技能。

SKILL.md
--- frontmatter
name: aws-cli-ec2
description: Use when working with AWS EC2 and Auto Scaling commands for ECS infrastructure — instances, VPCs, subnets, security groups, key pairs, AMIs, launch templates, auto scaling groups. Use this skill when launching or managing EC2 instances for ECS container instances, creating VPC networking (VPCs, subnets, internet gateways, NAT gateways, route tables), configuring security groups for ECS traffic, finding ECS-optimized AMIs, creating launch templates for ECS auto scaling, or managing auto scaling groups for ECS capacity providers.

AWS CLI v2 — EC2 & Auto Scaling (ECS-Relevant)

Overview

Reference for aws ec2 and aws autoscaling subcommands relevant to deploying ECS on EC2. Scoped to infrastructure commands needed for ECS clusters — not the full 400+ EC2 command set.

Quick Reference — Common Workflows

Find latest ECS-optimized AMI

bash
aws ec2 describe-images \
  --owners amazon \
  --filters "Name=name,Values=amzn2-ami-ecs-hvm-*-x86_64-ebs" \
  --query 'Images | sort_by(@, &CreationDate) | [-1].[ImageId,Name]' \
  --output text

Create VPC + subnet for ECS

bash
aws ec2 create-vpc --cidr-block 10.0.0.0/16 --query 'Vpc.VpcId' --output text
aws ec2 create-subnet --vpc-id vpc-xxx --cidr-block 10.0.1.0/24 --availability-zone us-east-1a
aws ec2 create-internet-gateway --query 'InternetGateway.InternetGatewayId' --output text
aws ec2 attach-internet-gateway --internet-gateway-id igw-xxx --vpc-id vpc-xxx

Create security group for ECS

bash
aws ec2 create-security-group --group-name ecs-sg --description "ECS instances" --vpc-id vpc-xxx
aws ec2 authorize-security-group-ingress --group-id sg-xxx --protocol tcp --port 80 --cidr 0.0.0.0/0

Create launch template for ECS instances

bash
aws ec2 create-launch-template --launch-template-name ecs-lt \
  --launch-template-data '{
    "ImageId":"ami-xxx",
    "InstanceType":"t3.medium",
    "IamInstanceProfile":{"Name":"ecsInstanceRole"},
    "UserData":"#!/bin/bash\necho ECS_CLUSTER=my-cluster >> /etc/ecs/ecs.config"
  }'

Covered Command Groups

GroupCommandsCLI Service
Instancesrun, describe, terminate, start, stop, rebootaws ec2
Security Groupscreate, delete, describe, authorize/revoke ingress/egressaws ec2
VPCvpc, subnet, igw, route-table, nat-gateway, elastic-ipaws ec2
Key Pairscreate, delete, describe, importaws ec2
AMIsdescribe-imagesaws ec2
Launch Templatescreate, delete, describe, versions, modifyaws ec2
Auto Scalingcreate/delete/describe/update ASG, launch configurationsaws autoscaling

Command Reference

See references/index.md for the quick reference table and global options.

GroupFileCommands
Instancesinstances.mdrun-instances, describe-instances, terminate-instances, start-instances, stop-instances, reboot-instances
Security Groupssecurity-groups.mdcreate-security-group, delete-security-group, describe-security-groups, authorize-security-group-ingress, authorize-security-group-egress, revoke-security-group-ingress, revoke-security-group-egress
VPCvpc.mdcreate-vpc, delete-vpc, describe-vpcs, modify-vpc-attribute, create-subnet, delete-subnet, describe-subnets, create-internet-gateway, delete-internet-gateway, attach-internet-gateway, detach-internet-gateway, describe-internet-gateways, create-route-table, delete-route-table, describe-route-tables, create-route, delete-route, associate-route-table, disassociate-route-table, create-nat-gateway, delete-nat-gateway, describe-nat-gateways, allocate-address, release-address, describe-addresses
Key Pairskey-pairs.mdcreate-key-pair, delete-key-pair, describe-key-pairs, import-key-pair
AMIsamis.mddescribe-images
Launch Templateslaunch-templates.mdcreate-launch-template, delete-launch-template, describe-launch-templates, describe-launch-template-versions, create-launch-template-version, modify-launch-template
Auto Scalingauto-scaling.mdcreate-auto-scaling-group, delete-auto-scaling-group, describe-auto-scaling-groups, update-auto-scaling-group, create-launch-configuration, delete-launch-configuration, describe-launch-configurations