gpt4 book ai didi

amazon-web-services - 尝试创建跨堆栈引用时出现 Yaml 格式错误

转载 作者:行者123 更新时间:2023-12-03 07:26:20 27 4
gpt4 key购买 nike

我正在尝试创建跨堆栈引用。将我引用的堆栈视为主 VPC,而我现在创建的堆栈基本上是在主 VPC 中创建一个子网,然后与另一个账户共享它(VPC/资源共享)。当我在 aws Designer 中验证此模板时,我在第 15 行收到 Yaml 格式不正确的错误,即:
CidrBlock: !选择 [ 0, !Cidr [!ImportValue'Fn::Sub': '${NetworkStackParameter}-VPCCIDR', 3, 8]]我对编码和云形成很陌生,所以我感谢任何帮助。请参阅下面的模板:

    AWSTemplateFormatVersion: "2010-09-09"
#Description:

Parameters:
NetworkStackParameter:
Type: String

Resources:
#Create Private Subnet ABC
PrivateSubnetABC:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: !Select [ 0, !Cidr [!ImportValue
'Fn::Sub': '${NetworkStackParameter}-VPCCIDR', 3, 8]]
VpcId: !ImportValue
'Fn::Sub': '${NetworkStackParameter}-VPCID'
AvailabilityZone: "us-east-1a"
Tags:
- Key: "name"
Value: "PrivateSubnetABC"

#Create Resource Share
PrivateSubnetABCShare:
Type: AWS::RAM::ResourceShare
Properties:
# AllowExternalPrincipals: Boolean
Name: "Service ABC"
# PermissionArns:
# - String
Principals:
- "1234567890"
ResourceArns:
- !Sub 'arn:aws:ec2:${AWS::Region}:${AWS::AccountId}:subnet/${PrivateSubnetABC}'
# Tags:
# - Tag

最佳答案

在这种情况下,将其编写为单独的 block 要容易得多,而不是尝试在一行中完成:

Resources:
#Create Private Subnet ABC
PrivateSubnetABC:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: !Select
- 0
- !Cidr
- !ImportValue
'Fn::Sub': '${NetworkStackParameter}-VPCCIDR'
- 3
- 8
VpcId: !ImportValue
'Fn::Sub': '${NetworkStackParameter}-VPCID'
AvailabilityZone: "us-east-1a"
Tags:
- Key: "name"
Value: "PrivateSubnetABC"

关于amazon-web-services - 尝试创建跨堆栈引用时出现 Yaml 格式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72581448/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com