AWS EC2实例可以通过一个或多个弹性IP地址来访问。针对单个EC2实例的多个IP地址需要在VPC子网中配置多个网络接口。以下是使用AWS CLI创建具有多个IP地址的EC2实例的示例代码:
#创建VPC
aws ec2 create-vpc --cidr-block 10.0.0.0/16
#创建子网
aws ec2 create-subnet --vpc-id vpc-12345 --cidr-block 10.0.0.0/24
#创建网络接口1
aws ec2 create-network-interface --subnet-id subnet-12345 --private-ip-address 10.0.0.5
#创建网络接口2
aws ec2 create-network-interface --subnet-id subnet-12345 --private-ip-address 10.0.0.6
#启动EC2实例
aws ec2 run-instances --image-id