【发布时间】:2019-08-10 18:59:47
【问题描述】:
我正在尝试在两个不同区域之间进行 vpc 对等互连。 在这里,我已经创建了资源,现在我只想将它们的 id 作为参数传递。在同一地区,我可以在两个 VPC 之间进行对等。但是由于 route_id 不存在,我在两个不同的区域遇到错误。
我的模板如下:
AWSTemplateFormatVersion: '2010-09-09'
Description: ''
Parameters:
PeerVPCAccountId:
Type: String
Description: "Peer VPC Account ID"
Default: (Acc_id)
PeerVPCRegion:
Type: String
Description: "Peer Region"
Default: (region)
VPC1:
Description: VPC Id of DataPipeline
Type: AWS::EC2::VPC::Id
Default: (vpc_id)
VPC1CIDRRange:
Description: The IP address range of DataPipeline VPC.
Type: String
MinLength: '9'
MaxLength: '18'
Default: (vpc_range)
AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
VPC1PrivateSubnet1CIDRRange:
Description: The IP address range for Private Subnet 1 in DataPipeline.
Type: String
MinLength: '9'
MaxLength: '18'
Default: (vpc_subnet_range)
AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
VPC1Private1Route:
Description: RouteTableId of Private Subnet 1 for DataPipeline
Type: String
Default: (vpc_subnet_route_id)
VPC2:
Description: VPC Id of PII-Isolation Pipeline
Type: String
Default: (vpc_id)
VPC2CIDRRange:
Description: The IP address range of PII Pipeline VPC.
Type: String
MinLength: '9'
MaxLength: '18'
AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
Default: (vpc_range)
VPC2PrivateSubnet1CIDRRange:
Description: The IP address range for Private Subnet 1 in PII Pipeline.
Type: String
MinLength: '9'
MaxLength: '18'
AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
Default: (vpc_subnet_range)
VPC2Private1Route:
Description: RouteTableId of Private Subnet 1 for PII Pipeline
Type: String
Default: (vpc_subnet_route_id)
Resources:
peerRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Statement:
- Principal:
AWS: !Ref PeerVPCAccountId
Action:
- 'sts:AssumeRole'
Effect: Allow
Path: /
Policies:
- PolicyName: root
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: 'ec2:AcceptVpcPeeringConnection'
Resource: '*'
VPC1Private1PeeringRoute1:
Type: AWS::EC2::Route
Properties:
DestinationCidrBlock:
Ref: VPC2PrivateSubnet1CIDRRange
RouteTableId:
Ref: VPC1Private1Route
VpcPeeringConnectionId:
Ref: myVPCPeeringConnection
VPC2Private1PeeringRoute1:
Type: AWS::EC2::Route
Properties:
DestinationCidrBlock:
Ref: VPC1PrivateSubnet1CIDRRange
RouteTableId:
Ref: VPC2Private1Route
VpcPeeringConnectionId:
Ref: myVPCPeeringConnection
myVPCPeeringConnection:
Type: AWS::EC2::VPCPeeringConnection
Properties:
VpcId:
Ref: VPC1
PeerVpcId:
Ref: VPC2
PeerOwnerId:
Ref: PeerVPCAccountId
PeerRegion:
Ref: PeerVPCRegion
PeerRoleArn: !GetAtt
- peerRole
- Arn
我已经给出了模板想要的所有内容,但仍然显示此错误。 有人可以帮忙修改或指出错误吗?
【问题讨论】:
-
您正在尝试构建两个 VPC,每个 VPC 位于不同的区域?这将不起作用,因为 CloudFormation 堆栈仅部署在一个区域中。您可以考虑使用AWS CloudFormation StackSets。
-
没有@JohnRotenstein。我已经创建了两个 VPC。弗吉尼亚北部 1 个,俄勒冈州 1 个。每个 VPC 有 2 个私有子网,我想在它们之间进行对等。根据我在 CFT 模板中提供 VPC 的 id 作为参数。
-
但是您的模板正在尝试创建
VPC1Private1PeeringRoute1(从 VPC1 到 VPC2)ANDVPC2Private1PeeringRoute1(从 VPC2 到 VPC1)。您不能在同一个模板中执行此操作,因为这些 VPC 位于不同的区域。您应该将模板一分为二——每个区域一个。 -
首先我想澄清一下,您问:“您正在尝试构建两个 VPC,每个 VPC 位于不同的区域?”这意味着您在问我您是否在此模板中在不同区域创建两个新 VPC?”。所以答案是我已经创建了两个 VPC。1 个在弗吉尼亚州北部,1 个在俄勒冈州。每个 VPC 有 2 个私有子网,我想他们之间的对等点。根据我在 CFT 模板中提供 VPC 的 id 作为参数。你说我正在尝试创建
VPC1Private1PeeringRoute。这只是在两个不同区域的不同子网之间创建路由。 -
VPC1Private1PeeringRoute1和 `VPC2Private1PeeringRoute1 正在为来自不同区域的两个 VPC 之间创建路由以进行对等互连。我认为,按照这个link,我们可以做到这一点。
标签: amazon-cloudformation amazon-vpc subnet