gpt4 book ai didi

amazon-web-services - AWS Cloudformation 嵌套内部函数不评估

转载 作者:行者123 更新时间:2023-12-04 08:11:46 24 4
gpt4 key购买 nike

这是我正在编写的 cloudformation 模板的一部分,使用 Fn::FindInMap 函数出现错误:

Parameters:
VpcStackName:
Description: >-
Name of an active CloudFormation VPC stack that contains the networking
resources, such as the subnet and security group, that will be used in
this stack.
Type: String
MinLength: 1
MaxLength: 255
AllowedPattern: '^[a-zA-Z][-a-zA-Z0-9]*$'
Default: wordpress-dev-vpc

Mappings:
Instance:
development:
AllocatedStorage: 20
DBInstanceClass: db.t2.micro
production:
AllocatedStorage: 25
DBInstanceClass: db.m3.medium

Resources:
DBInstance:
Type: AWS::RDS::DBInstance
DeletionPolicy: Snapshot
Properties:
Engine: MariaDB
StorageType: gp2
MasterUsername: !Ref MasterUsername
MasterUserPassword: !Ref MasterUserPassword
AllocatedStorage:
Fn::FindInMap:
- Instance
- Fn::ImportValue:
Fn::Sub: '${VpcStackName}-Environment'
- AllocatedStorage
DBInstanceClass:
Fn::FindInMap:
- Instance
- Fn::ImportValue:
Fn::Sub: '${VpcStackName}-Environment'
- DBInstanceClass

在另一个堆栈中,我正在导出 ${VpcStackName}-Environment,如下所示:

Outputs:
Environment:
Description: Environment type of this stack
Value: !Ref Environment
Export:
Name: !Sub '${AWS::StackName}-Environment'

尝试使用 Fn::FindInMap 函数时,出现此错误:

An error occurred (ValidationError) when calling the ValidateTemplate operation: Template error: every Fn::FindInMap object requires three parameters, the map name, map key and the attribute for return value

有什么建议吗?

基于https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-findinmap.html处的文档,Fn::FindInMap 函数中支持的函数是 Fn::FindInMapRef。那么还有其他方法吗?例如,将 Fn::ImportValue: !Sub '${VpcStackName}-Environment' 的值存储在临时变量中?

最佳答案

根据this文档中,Fn::FindInMap 函数仅适用于以下内容:

  • Fn::FindInMap
  • 引用

因此 Fn::ImportValueFn::Sub 将不会被评估。

关于amazon-web-services - AWS Cloudformation 嵌套内部函数不评估,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50150772/

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