Amazon web services 如何在嵌套堆栈中使用AWS CloudFormation模板中的映射 我们考虑下面的映射< /代码>和 FindInMap 用于同一个AWS云计算模板中。他们会成功的 现在,考虑 VPCIDs/COD> 映射> > YAML< /COD>模板,我试图从嵌套.yAML模板中使用< 映射> >代码> 模板。
我怎样才能做到这一点Amazon web services 如何在嵌套堆栈中使用AWS CloudFormation模板中的映射 我们考虑下面的映射< /代码>和 FindInMap 用于同一个AWS云计算模板中。他们会成功的 现在,考虑 VPCIDs/COD> 映射> > YAML< /COD>模板,我试图从嵌套.yAML模板中使用< 映射> >代码> 模板。,amazon-web-services,mapping,amazon-cloudformation,nested-stack,Amazon Web Services,Mapping,Amazon Cloudformation,Nested Stack,我怎样才能做到这一点 # master.yaml Mappings: VpcIds: us-east-1: "123456789012": "vpc-00011122233344455" "234567890123": "vpc-11122233344455566" us-west-1: "123456789012": "vpc
# master.yaml
Mappings:
VpcIds:
us-east-1:
"123456789012": "vpc-00011122233344455"
"234567890123": "vpc-11122233344455566"
us-west-1:
"123456789012": "vpc-22233344455566677"
"234567890123": "vpc-33344455566677788"
# nested.yaml
Resources:
EgressOnlyInternetGateway:
Type: AWS::EC2::EgressOnlyInternetGateway
Properties:
VpcId: !FindInMap [VpcIds, !Ref "AWS::Region", !Ref "AWS::AccountId"]
更新:我试图使用MyTestMasterStack
中定义的映射参数在MyTestNestedStack
(MyTestNestedStack.yaml
)中创建一个资源MyTestNestedSg
,如下所示。我收到错误:针对MyTestNestedStack
为不需要参数值的模板指定的参数值
我如何解决这个问题
请注意,MyTestMasterStack
下的资源MyTestMasterSg
只是为了完整性
# MyTestMasterStack.yaml
Mappings:
VpcIds:
us-east-1:
"123456789012": "vpc-00011122233344455"
"234567890123": "vpc-11122233344455566"
Resources:
MyTestNestedStack:
Type: AWS::CloudFormation::Stack
Properties:
Parameters:
VpcId: !FindInMap [VpcIds, !Ref "AWS::Region", !Ref "AWS::AccountId"]
TemplateURL: "https://s3.amazonaws.com/my_template_bucket_name/MyTestNestedStack.yaml"
TimeoutInMinutes: 60
MyTestMasterSg:
Type: AWS::EC2::SecurityGroup
Properties:
VpcId: "vpc-017a12485ad93e94a"
GroupDescription: Testing resource creation wtih Mappings from the parent Stack
GroupName: MyTestMasterSg
SecurityGroupIngress:
- CidrIp: 10.1.0.0/16
FromPort: 80
IpProtocol: tcp
ToPort: 80
# MyTestNestedStack.yaml
Resources:
MyTestNestedSg:
Type: AWS::EC2::SecurityGroup
Properties:
VpcId: !Ref VpcId
GroupDescription: Testing resource creation wtih Mappings from the parent Stack
GroupName: MyTestNestedSg
SecurityGroupIngress:
- CidrIp: 10.1.0.0/16
FromPort: 8080
IpProtocol: tcp
ToPort: 8080
你不能这样做。您必须将解析的映射值传递到AWS::CloudFormation::Stack
资源
嵌套堆栈应该是自给自足的,并且它们无权访问父堆栈的参数、映射或资源。它们只能处理您显式通过AWS::CloudFormation::Stack
资源的参数传递的数据
因此,在父级堆栈中,您必须执行以下操作:
MyNestedStack:
Type: AWS::CloudFormation::Stack
Properties:
Parameters:
VpcId : !FindInMap [VpcIds, !Ref "AWS::Region", !Ref "AWS::AccountId"]
TemplateURL: String
更新
您的MyTestNestedStack.yaml
缺少参数
:
Parameters:
VpcId:
Type: AWS::EC2::VPC::Id
感谢@Marcin的及时回复。我遵循了这一点。然后我在MyNestedStack
模板中,使用了这个引用VpcId:!请参考VpcId
,以创建安全组,但该操作失败,为不需要它们的模板指定了错误参数值。
针对MyNestedStack
。不确定我是否遗漏了其他内容。@Rafiq您能用模板的当前状态更新您的问题吗?谢谢@Marcin。请查看更新。@Rafiq I更新了答案。请看一看。