aws-ec2

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

AWS EC2

AWS EC2

Deploy and manage Amazon EC2 compute instances for production, staging, and development workloads.
为生产、预发布和开发工作负载部署和管理Amazon EC2计算实例。

When to Use This Skill

何时使用此技能

  • Launching new compute instances for application hosting
  • Building golden AMIs for consistent deployments
  • Setting up auto-scaling groups behind load balancers
  • Migrating workloads to Spot instances for cost savings
  • Troubleshooting instance connectivity, performance, or launch failures
  • Creating launch templates for repeatable infrastructure
  • 启动用于应用托管的新计算实例
  • 构建用于一致部署的黄金AMI
  • 在负载均衡器后方设置自动扩缩容组
  • 将工作负载迁移到Spot实例以节省成本
  • 排查实例连接性、性能或启动故障
  • 创建用于可重复基础设施的启动模板

Prerequisites

前提条件

  • AWS CLI v2 installed and configured (
    aws configure
    )
  • IAM permissions:
    ec2:*
    ,
    autoscaling:*
    ,
    elasticloadbalancing:*
    ,
    iam:PassRole
  • An existing VPC with subnets (see aws-vpc)
  • SSH key pair created (
    aws ec2 create-key-pair --key-name my-key --query 'KeyMaterial' --output text > my-key.pem
    )
  • 已安装并配置AWS CLI v2(
    aws configure
  • IAM权限:
    ec2:*
    ,
    autoscaling:*
    ,
    elasticloadbalancing:*
    ,
    iam:PassRole
  • 已存在带子网的VPC(参见 aws-vpc
  • 已创建SSH密钥对(
    aws ec2 create-key-pair --key-name my-key --query 'KeyMaterial' --output text > my-key.pem

Instance Type Selection Guide

实例类型选择指南

CategoryTypesUse Case
General Purposet3, t3a, m6i, m7gWeb servers, small databases, dev/test
Compute Optimizedc6i, c7gBatch processing, media encoding, ML inference
Memory Optimizedr6i, r7g, x2idnIn-memory caches, large databases
Storage Optimizedi3, i4i, d3Data warehousing, distributed file systems
Acceleratedp4d, g5, inf2ML training, GPU rendering, inference
Burstablet3.micro-t3.2xlargeLow-steady-state with occasional bursts
类别类型适用场景
通用型t3, t3a, m6i, m7gWeb服务器、小型数据库、开发/测试
计算优化型c6i, c7g批处理、媒体编码、ML推理
内存优化型r6i, r7g, x2idn内存缓存、大型数据库
存储优化型i3, i4i, d3数据仓库、分布式文件系统
加速型p4d, g5, inf2ML训练、GPU渲染、推理
突发性能型t3.micro-t3.2xlarge低稳态负载且偶尔需要突发性能

Launch an Instance

启动实例

bash
undefined
bash
undefined

Launch a production web server

Launch a production web server

aws ec2 run-instances
--image-id ami-0abcdef1234567890
--instance-type t3.medium
--key-name my-key
--security-group-ids sg-12345678
--subnet-id subnet-12345678
--iam-instance-profile Name=EC2AppProfile
--metadata-options "HttpTokens=required,HttpEndpoint=enabled"
--block-device-mappings '[{ "DeviceName": "/dev/xvda", "Ebs": { "VolumeSize": 30, "VolumeType": "gp3", "Iops": 3000, "Throughput": 125, "Encrypted": true } }]'
--tag-specifications 'ResourceType=instance,Tags=[ {Key=Name,Value=web-server-01}, {Key=Environment,Value=production}, {Key=Team,Value=platform} ]'
--user-data file://userdata.sh
aws ec2 run-instances
--image-id ami-0abcdef1234567890
--instance-type t3.medium
--key-name my-key
--security-group-ids sg-12345678
--subnet-id subnet-12345678
--iam-instance-profile Name=EC2AppProfile
--metadata-options "HttpTokens=required,HttpEndpoint=enabled"
--block-device-mappings '[{ "DeviceName": "/dev/xvda", "Ebs": { "VolumeSize": 30, "VolumeType": "gp3", "Iops": 3000, "Throughput": 125, "Encrypted": true } }]'
--tag-specifications 'ResourceType=instance,Tags=[ {Key=Name,Value=web-server-01}, {Key=Environment,Value=production}, {Key=Team,Value=platform} ]'
--user-data file://userdata.sh

Launch with IMDSv2 required (security best practice)

Launch with IMDSv2 required (security best practice)

aws ec2 run-instances
--image-id ami-0abcdef1234567890
--instance-type t3.micro
--metadata-options "HttpTokens=required,HttpPutResponseHopLimit=1,HttpEndpoint=enabled"
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=secure-instance}]'
undefined
aws ec2 run-instances
--image-id ami-0abcdef1234567890
--instance-type t3.micro
--metadata-options "HttpTokens=required,HttpPutResponseHopLimit=1,HttpEndpoint=enabled"
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=secure-instance}]'
undefined

User Data Scripts

用户数据脚本

bash
#!/bin/bash
bash
#!/bin/bash

userdata.sh - Bootstrap a web server on Amazon Linux 2023

userdata.sh - Bootstrap a web server on Amazon Linux 2023

set -euxo pipefail
set -euxo pipefail

System updates

System updates

dnf update -y
dnf update -y

Install and start web server

Install and start web server

dnf install -y nginx systemctl enable nginx systemctl start nginx
dnf install -y nginx systemctl enable nginx systemctl start nginx

Install CloudWatch agent

Install CloudWatch agent

dnf install -y amazon-cloudwatch-agent /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl
-a fetch-config -m ec2
-s -c ssm:AmazonCloudWatch-linux
dnf install -y amazon-cloudwatch-agent /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl
-a fetch-config -m ec2
-s -c ssm:AmazonCloudWatch-linux

Install CodeDeploy agent

Install CodeDeploy agent

dnf install -y ruby wget cd /home/ec2-user wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install chmod +x ./install ./install auto
dnf install -y ruby wget cd /home/ec2-user wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install chmod +x ./install ./install auto

Signal CloudFormation (if launched via CFN)

Signal CloudFormation (if launched via CFN)

/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource ASG --region ${AWS::Region}

/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource ASG --region ${AWS::Region}

undefined
undefined

Launch Templates

启动模板

bash
undefined
bash
undefined

Create a launch template with full configuration

Create a launch template with full configuration

aws ec2 create-launch-template
--launch-template-name web-server-template
--version-description "v1 - AL2023 with nginx"
--launch-template-data '{ "ImageId": "ami-0abcdef1234567890", "InstanceType": "t3.medium", "KeyName": "my-key", "SecurityGroupIds": ["sg-12345678"], "IamInstanceProfile": {"Name": "EC2AppProfile"}, "MetadataOptions": { "HttpTokens": "required", "HttpEndpoint": "enabled" }, "BlockDeviceMappings": [{ "DeviceName": "/dev/xvda", "Ebs": { "VolumeSize": 30, "VolumeType": "gp3", "Encrypted": true } }], "TagSpecifications": [{ "ResourceType": "instance", "Tags": [ {"Key": "Environment", "Value": "production"}, {"Key": "ManagedBy", "Value": "launch-template"} ] }], "Monitoring": {"Enabled": true}, "UserData": "'"$(base64 -w0 userdata.sh)"'" }'
aws ec2 create-launch-template
--launch-template-name web-server-template
--version-description "v1 - AL2023 with nginx"
--launch-template-data '{ "ImageId": "ami-0abcdef1234567890", "InstanceType": "t3.medium", "KeyName": "my-key", "SecurityGroupIds": ["sg-12345678"], "IamInstanceProfile": {"Name": "EC2AppProfile"}, "MetadataOptions": { "HttpTokens": "required", "HttpEndpoint": "enabled" }, "BlockDeviceMappings": [{ "DeviceName": "/dev/xvda", "Ebs": { "VolumeSize": 30, "VolumeType": "gp3", "Encrypted": true } }], "TagSpecifications": [{ "ResourceType": "instance", "Tags": [ {"Key": "Environment", "Value": "production"}, {"Key": "ManagedBy", "Value": "launch-template"} ] }], "Monitoring": {"Enabled": true}, "UserData": "'"$(base64 -w0 userdata.sh)"'" }'

Create a new version of the launch template

Create a new version of the launch template

aws ec2 create-launch-template-version
--launch-template-name web-server-template
--source-version 1
--version-description "v2 - updated AMI"
--launch-template-data '{"ImageId": "ami-0newami1234567890"}'
aws ec2 create-launch-template-version
--launch-template-name web-server-template
--source-version 1
--version-description "v2 - updated AMI"
--launch-template-data '{"ImageId": "ami-0newami1234567890"}'

Set the default version

Set the default version

aws ec2 modify-launch-template
--launch-template-name web-server-template
--default-version 2
undefined
aws ec2 modify-launch-template
--launch-template-name web-server-template
--default-version 2
undefined

Auto Scaling Group

自动扩缩容组

bash
undefined
bash
undefined

Create ASG with mixed instances (on-demand + spot)

Create ASG with mixed instances (on-demand + spot)

aws autoscaling create-auto-scaling-group
--auto-scaling-group-name web-asg
--mixed-instances-policy '{ "LaunchTemplate": { "LaunchTemplateSpecification": { "LaunchTemplateName": "web-server-template", "Version": "$Default" }, "Overrides": [ {"InstanceType": "t3.medium"}, {"InstanceType": "t3a.medium"}, {"InstanceType": "m5.large"} ] }, "InstancesDistribution": { "OnDemandBaseCapacity": 2, "OnDemandPercentageAboveBaseCapacity": 25, "SpotAllocationStrategy": "capacity-optimized" } }'
--min-size 2 --max-size 10 --desired-capacity 4
--vpc-zone-identifier "subnet-aaa,subnet-bbb"
--target-group-arns "arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/web-tg/abc123"
--health-check-type ELB
--health-check-grace-period 300
--tags '[ {"Key":"Name","Value":"web-asg","PropagateAtLaunch":true}, {"Key":"Environment","Value":"production","PropagateAtLaunch":true} ]'
aws autoscaling create-auto-scaling-group
--auto-scaling-group-name web-asg
--mixed-instances-policy '{ "LaunchTemplate": { "LaunchTemplateSpecification": { "LaunchTemplateName": "web-server-template", "Version": "$Default" }, "Overrides": [ {"InstanceType": "t3.medium"}, {"InstanceType": "t3a.medium"}, {"InstanceType": "m5.large"} ] }, "InstancesDistribution": { "OnDemandBaseCapacity": 2, "OnDemandPercentageAboveBaseCapacity": 25, "SpotAllocationStrategy": "capacity-optimized" } }'
--min-size 2 --max-size 10 --desired-capacity 4
--vpc-zone-identifier "subnet-aaa,subnet-bbb"
--target-group-arns "arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/web-tg/abc123"
--health-check-type ELB
--health-check-grace-period 300
--tags '[ {"Key":"Name","Value":"web-asg","PropagateAtLaunch":true}, {"Key":"Environment","Value":"production","PropagateAtLaunch":true} ]'

Create target tracking scaling policy (target 60% CPU)

Create target tracking scaling policy (target 60% CPU)

aws autoscaling put-scaling-policy
--auto-scaling-group-name web-asg
--policy-name cpu-target-tracking
--policy-type TargetTrackingScaling
--target-tracking-configuration '{ "PredefinedMetricSpecification": { "PredefinedMetricType": "ASGAverageCPUUtilization" }, "TargetValue": 60.0, "ScaleInCooldown": 300, "ScaleOutCooldown": 60 }'
aws autoscaling put-scaling-policy
--auto-scaling-group-name web-asg
--policy-name cpu-target-tracking
--policy-type TargetTrackingScaling
--target-tracking-configuration '{ "PredefinedMetricSpecification": { "PredefinedMetricType": "ASGAverageCPUUtilization" }, "TargetValue": 60.0, "ScaleInCooldown": 300, "ScaleOutCooldown": 60 }'

Create scheduled scaling for known traffic patterns

Create scheduled scaling for known traffic patterns

aws autoscaling put-scheduled-update-group-action
--auto-scaling-group-name web-asg
--scheduled-action-name scale-up-morning
--recurrence "0 8 * * MON-FRI"
--min-size 4 --max-size 20 --desired-capacity 8
aws autoscaling put-scheduled-update-group-action
--auto-scaling-group-name web-asg
--scheduled-action-name scale-down-evening
--recurrence "0 20 * * MON-FRI"
--min-size 2 --max-size 10 --desired-capacity 2
undefined
aws autoscaling put-scheduled-update-group-action
--auto-scaling-group-name web-asg
--scheduled-action-name scale-up-morning
--recurrence "0 8 * * MON-FRI"
--min-size 4 --max-size 20 --desired-capacity 8
aws autoscaling put-scheduled-update-group-action
--auto-scaling-group-name web-asg
--scheduled-action-name scale-down-evening
--recurrence "0 20 * * MON-FRI"
--min-size 2 --max-size 10 --desired-capacity 2
undefined

Spot Instances

Spot实例

bash
undefined
bash
undefined

Request Spot instances

Request Spot instances

aws ec2 request-spot-instances
--spot-price "0.05"
--instance-count 3
--type "one-time"
--launch-specification '{ "ImageId": "ami-0abcdef1234567890", "InstanceType": "c5.xlarge", "KeyName": "my-key", "SecurityGroupIds": ["sg-12345678"], "SubnetId": "subnet-12345678" }'
aws ec2 request-spot-instances
--spot-price "0.05"
--instance-count 3
--type "one-time"
--launch-specification '{ "ImageId": "ami-0abcdef1234567890", "InstanceType": "c5.xlarge", "KeyName": "my-key", "SecurityGroupIds": ["sg-12345678"], "SubnetId": "subnet-12345678" }'

Check current Spot prices

Check current Spot prices

aws ec2 describe-spot-price-history
--instance-types t3.medium t3a.medium m5.large
--availability-zone us-east-1a
--product-descriptions "Linux/UNIX"
--start-time "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
--query "SpotPriceHistory[].{Type:InstanceType,Price:SpotPrice,AZ:AvailabilityZone}"
--output table
aws ec2 describe-spot-price-history
--instance-types t3.medium t3a.medium m5.large
--availability-zone us-east-1a
--product-descriptions "Linux/UNIX"
--start-time "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
--query "SpotPriceHistory[].{Type:InstanceType,Price:SpotPrice,AZ:AvailabilityZone}"
--output table

Create a Spot Fleet request

Create a Spot Fleet request

aws ec2 request-spot-fleet
--spot-fleet-request-config '{ "IamFleetRole": "arn:aws:iam::123456789012:role/aws-ec2-spot-fleet-role", "TargetCapacity": 10, "SpotPrice": "0.10", "AllocationStrategy": "capacityOptimized", "LaunchSpecifications": [ {"ImageId": "ami-xxx", "InstanceType": "c5.xlarge", "SubnetId": "subnet-aaa"}, {"ImageId": "ami-xxx", "InstanceType": "c5a.xlarge", "SubnetId": "subnet-bbb"} ] }'
undefined
aws ec2 request-spot-fleet
--spot-fleet-request-config '{ "IamFleetRole": "arn:aws:iam::123456789012:role/aws-ec2-spot-fleet-role", "TargetCapacity": 10, "SpotPrice": "0.10", "AllocationStrategy": "capacityOptimized", "LaunchSpecifications": [ {"ImageId": "ami-xxx", "InstanceType": "c5.xlarge", "SubnetId": "subnet-aaa"}, {"ImageId": "ami-xxx", "InstanceType": "c5a.xlarge", "SubnetId": "subnet-bbb"} ] }'
undefined

AMI Management

AMI管理

bash
undefined
bash
undefined

Create an AMI from a running instance

Create an AMI from a running instance

aws ec2 create-image
--instance-id i-0abc123def456
--name "web-server-$(date +%Y%m%d)"
--description "Web server golden AMI"
--no-reboot
--tag-specifications 'ResourceType=image,Tags=[ {Key=Name,Value=web-server-golden}, {Key=Version,Value=2026.03.24} ]'
aws ec2 create-image
--instance-id i-0abc123def456
--name "web-server-$(date +%Y%m%d)"
--description "Web server golden AMI"
--no-reboot
--tag-specifications 'ResourceType=image,Tags=[ {Key=Name,Value=web-server-golden}, {Key=Version,Value=2026.03.24} ]'

Copy AMI to another region for disaster recovery

Copy AMI to another region for disaster recovery

aws ec2 copy-image
--source-image-id ami-0abcdef1234567890
--source-region us-east-1
--region us-west-2
--name "web-server-dr-copy"
aws ec2 copy-image
--source-image-id ami-0abcdef1234567890
--source-region us-east-1
--region us-west-2
--name "web-server-dr-copy"

Deregister old AMIs and delete associated snapshots

Deregister old AMIs and delete associated snapshots

aws ec2 deregister-image --image-id ami-old123 aws ec2 delete-snapshot --snapshot-id snap-old123
aws ec2 deregister-image --image-id ami-old123 aws ec2 delete-snapshot --snapshot-id snap-old123

Share AMI with another AWS account

Share AMI with another AWS account

aws ec2 modify-image-attribute
--image-id ami-0abcdef1234567890
--launch-permission "Add=[{UserId=987654321098}]"
undefined
aws ec2 modify-image-attribute
--image-id ami-0abcdef1234567890
--launch-permission "Add=[{UserId=987654321098}]"
undefined

Instance Management

实例管理

bash
undefined
bash
undefined

List running instances with key details

List running instances with key details

aws ec2 describe-instances
--filters "Name=instance-state-name,Values=running"
--query "Reservations[].Instances[].{ID:InstanceId,Type:InstanceType,IP:PrivateIpAddress,Name:Tags[?Key=='Name']|[0].Value,State:State.Name}"
--output table
aws ec2 describe-instances
--filters "Name=instance-state-name,Values=running"
--query "Reservations[].Instances[].{ID:InstanceId,Type:InstanceType,IP:PrivateIpAddress,Name:Tags[?Key=='Name']|[0].Value,State:State.Name}"
--output table

Stop and start instances

Stop and start instances

aws ec2 stop-instances --instance-ids i-0abc123def456 aws ec2 start-instances --instance-ids i-0abc123def456
aws ec2 stop-instances --instance-ids i-0abc123def456 aws ec2 start-instances --instance-ids i-0abc123def456

Resize an instance (stop first)

Resize an instance (stop first)

aws ec2 stop-instances --instance-ids i-0abc123def456 aws ec2 wait instance-stopped --instance-ids i-0abc123def456 aws ec2 modify-instance-attribute
--instance-id i-0abc123def456
--instance-type '{"Value": "t3.large"}' aws ec2 start-instances --instance-ids i-0abc123def456
aws ec2 stop-instances --instance-ids i-0abc123def456 aws ec2 wait instance-stopped --instance-ids i-0abc123def456 aws ec2 modify-instance-attribute
--instance-id i-0abc123def456
--instance-type '{"Value": "t3.large"}' aws ec2 start-instances --instance-ids i-0abc123def456

Get console output for debugging boot issues

Get console output for debugging boot issues

aws ec2 get-console-output --instance-id i-0abc123def456
aws ec2 get-console-output --instance-id i-0abc123def456

Get instance screenshot (helps debug GUI issues)

Get instance screenshot (helps debug GUI issues)

aws ec2 get-console-screenshot --instance-id i-0abc123def456
undefined
aws ec2 get-console-screenshot --instance-id i-0abc123def456
undefined

Terraform EC2 with Auto Scaling

Terraform配置EC2与自动扩缩容

hcl
resource "aws_launch_template" "web" {
  name_prefix   = "web-"
  image_id      = data.aws_ami.amazon_linux.id
  instance_type = "t3.medium"

  iam_instance_profile {
    name = aws_iam_instance_profile.web.name
  }

  metadata_options {
    http_tokens   = "required"
    http_endpoint = "enabled"
  }

  block_device_mappings {
    device_name = "/dev/xvda"
    ebs {
      volume_size = 30
      volume_type = "gp3"
      encrypted   = true
    }
  }

  user_data = base64encode(file("userdata.sh"))

  tag_specifications {
    resource_type = "instance"
    tags = {
      Name        = "web-server"
      Environment = "production"
    }
  }
}

resource "aws_autoscaling_group" "web" {
  name                = "web-asg"
  min_size            = 2
  max_size            = 10
  desired_capacity    = 4
  vpc_zone_identifier = [aws_subnet.private_a.id, aws_subnet.private_b.id]
  target_group_arns   = [aws_lb_target_group.web.arn]
  health_check_type   = "ELB"

  launch_template {
    id      = aws_launch_template.web.id
    version = "$Latest"
  }

  tag {
    key                 = "Name"
    value               = "web-asg"
    propagate_at_launch = true
  }
}

resource "aws_autoscaling_policy" "cpu" {
  name                   = "cpu-target-tracking"
  autoscaling_group_name = aws_autoscaling_group.web.name
  policy_type            = "TargetTrackingScaling"

  target_tracking_configuration {
    predefined_metric_specification {
      predefined_metric_type = "ASGAverageCPUUtilization"
    }
    target_value = 60.0
  }
}
hcl
resource "aws_launch_template" "web" {
  name_prefix   = "web-"
  image_id      = data.aws_ami.amazon_linux.id
  instance_type = "t3.medium"

  iam_instance_profile {
    name = aws_iam_instance_profile.web.name
  }

  metadata_options {
    http_tokens   = "required"
    http_endpoint = "enabled"
  }

  block_device_mappings {
    device_name = "/dev/xvda"
    ebs {
      volume_size = 30
      volume_type = "gp3"
      encrypted   = true
    }
  }

  user_data = base64encode(file("userdata.sh"))

  tag_specifications {
    resource_type = "instance"
    tags = {
      Name        = "web-server"
      Environment = "production"
    }
  }
}

resource "aws_autoscaling_group" "web" {
  name                = "web-asg"
  min_size            = 2
  max_size            = 10
  desired_capacity    = 4
  vpc_zone_identifier = [aws_subnet.private_a.id, aws_subnet.private_b.id]
  target_group_arns   = [aws_lb_target_group.web.arn]
  health_check_type   = "ELB"

  launch_template {
    id      = aws_launch_template.web.id
    version = "$Latest"
  }

  tag {
    key                 = "Name"
    value               = "web-asg"
    propagate_at_launch = true
  }
}

resource "aws_autoscaling_policy" "cpu" {
  name                   = "cpu-target-tracking"
  autoscaling_group_name = aws_autoscaling_group.web.name
  policy_type            = "TargetTrackingScaling"

  target_tracking_configuration {
    predefined_metric_specification {
      predefined_metric_type = "ASGAverageCPUUtilization"
    }
    target_value = 60.0
  }
}

Troubleshooting

故障排查

ProblemCauseFix
Instance stuck in
pending
Insufficient capacityTry a different AZ or instance type
Cannot SSH to instanceSecurity group or NACL blocks port 22Check SG ingress rules and route tables
Instance immediately terminatesEBS volume limit or AMI issueCheck
describe-instances
for StateReason
IMDSv1 deprecation warningsMetadata options not setSet
HttpTokens=required
in launch template
User data not runningScript missing shebang or not base64Verify
#!/bin/bash
header; check
/var/log/cloud-init-output.log
Spot instance terminatedCapacity reclaimed by AWSUse capacity-optimized allocation and diversify types
ASG not replacing unhealthyHealth check grace period too shortIncrease grace period to cover app boot time
EBS throughput bottleneckgp2 volume too small for IOPSMigrate to gp3 and set explicit IOPS/throughput
问题原因解决方法
实例卡在
pending
状态
容量不足尝试不同可用区或实例类型
无法通过SSH连接实例安全组或NACL阻止22端口检查安全组入站规则和路由表
实例立即终止EBS卷限制或AMI问题查看
describe-instances
中的StateReason
IMDSv1弃用警告未设置元数据选项在启动模板中设置
HttpTokens=required
用户数据未运行脚本缺少shebang或未进行base64编码验证
#!/bin/bash
开头;查看
/var/log/cloud-init-output.log
Spot实例被终止AWS回收容量使用容量优化分配策略并多样化实例类型
自动扩缩容组未替换不健康实例健康检查宽限期过短增加宽限期以覆盖应用启动时间
EBS吞吐量瓶颈gp2卷太小无法满足IOPS需求迁移到gp3并设置明确的IOPS/吞吐量

Related Skills

相关技能

  • aws-vpc - VPC networking, subnets, and security groups
  • aws-iam - Instance profiles and roles
  • aws-cost-optimization - Rightsizing and Spot strategies
  • terraform-aws - Infrastructure as Code deployment
  • cloudformation - AWS-native IaC templates
  • aws-vpc - VPC网络、子网和安全组
  • aws-iam - 实例配置文件和角色
  • aws-cost-optimization - 实例调整和Spot策略
  • terraform-aws - 基础设施即代码部署
  • cloudformation - AWS原生IaC模板