使用 AWS CLI 指定 t2 实例 VPC

Specify a t2 instance VPC using AWS CLI

t2 实例仅适用于 VPC(如此处记录:http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/t2-instances.html#t2-instances-vpc-support). So when running via AWS CLI, how do I specify a VPC on the command line? I've followed the document here (http://docs.aws.amazon.com/codedeploy/latest/userguide/how-to-set-up-new-instance.html)并具有概述的命令行设置:

aws ec2 run-instances \
  --image-id amiID \
  --key-name keyName \
  --user-data file://instance-setup.sh \
  --count 1 \
  --instance-type instanceType \
  --iam-instance-profile Name=CodeDeployDemo-EC2-Instance-Profile

我意识到使用 m3 实例可以按预期工作,但我想要一个 t2.micro,因为该实例将仅用于部署。

该命令将自动使用默认 VPC 和一个随机子网(也是select可用区)。如果您希望指定 VPC 和子网,请使用 --subnet-id 参数。

对于 select T2 实例,请务必包含实例类型标识符,例如 --instance-type t2.micro

此外,T2 实例需要为 HVM 配置 AMI(Windows 默认使用它,但 Linux 可以选择 PV 或 HVM)。