要创建一个跨多个子网/可用区的启动模板,您可以使用AWS CloudFormation。以下是一个使用CloudFormation模板创建EC2实例的示例:
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
KeyName:
Description: Name of an existing EC2 KeyPair to enable SSH access to the instances
Type: AWS::EC2::KeyPair::KeyName
InstanceType:
Description: EC2 instance type
Type: String
Default: t2.micro
AllowedValues:
- t2.micro
- t2.small
- t2.medium
ConstraintDescription: Must be a valid EC2 instance type.
Resources:
MyInstance:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-0c94855ba95c71c99
KeyName: !Ref KeyName
InstanceType: !Ref InstanceType
SubnetId: subnet-12345678
AvailabilityZone: us-west-2a
MyInstance2:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-0c94855ba95c71c99
KeyName: !Ref KeyName
InstanceType: !Ref InstanceType
SubnetId: subnet-87654321
AvailabilityZone: us-west-2b
在上面的示例中,我们创建了两个EC2实例(MyInstance和MyInstance2),分别位于不同的子网(subnet-12345678和subnet-87654321)和可用区(us-west-2a和us-west-2b)。您可以根据需要添加更多的EC2实例,并将它们分配给不同的子网和可用区。
您可以使用AWS CloudFormation控制台或AWS CLI等工具来部署此CloudFormation模板。一旦部署成功,您将在指定的子网和可用区中启动多个EC2实例。