问题描述
我正在尝试传入 CommaDelimitedList 以填充 AWS::ElasticLoadBalancingV2::ListenerCertificate
资源中的证书列表。
我尝试了几种格式,包括以下:
Parameters:
pAdditionalAlbListenerCertArns:
Type: CommaDelimitedList
Default: "arn:someCert1,arnsomeCert2"
Description: enter list of the ACM Certificates (Arns)
## Resource Format 1 - I would think this way would work as the result is [thing1,thing2]
Resources:
rCertificatesList:
Type: AWS::ElasticLoadBalancingV2::ListenerCertificate
Properties:
Certificates: ! Ref pAdditionalAlbListenerCertArns
## Resource Format 2 - I kNow this should not work,because it's a single item trying to be populated by a list.
Resources:
rCertificatesList:
Type: AWS::ElasticLoadBalancingV2::ListenerCertificate
Properties:
Certificates:
CertificateArn: ! Ref pAdditionalAlbListenerCertArns
显然 Cfn 不够聪明,无法在每个项目前加上 CertificateArn:
。
我还尝试了 !Split
、!Sub
和 !Join
的组合,但都出现了同样的错误。目前我不得不直接输入证书,这是不可行的。虽然我可以为每个证书创建单独的参数,或者使用 !Select
将它们从列表中取出,但我不知道在每个环境(DEV/TEST/PROD)中有多少个。
我知道这对于安全组之类的事情很有效;我错过了什么吗?
提前致谢!
解决方法
AWS::ElasticLoadBalancingV2::ListenerCertificate Certificate 的格式为:
Certificates:
- CertificateArn: String
您的任何用途都不会适用于此。事实上,什么都行不通,因为这需要循环,而 CloudFormation 不支持。实现您想要的唯一可行方法是开发您自己的 custom CFN macro。
换句话说,如果您需要在 CFN 代码中进行大量迭代,那么 CFN 可能不是适合您的工具。看看对循环有丰富支持的 CDK 或 terraform。