我正在尝试使用 Cloudformation 和无服务器框架创建一些资源,其中我需要替换另一个资源中的资源名称。尝试使用 !Sub
但仍然无法创建另一个资源的 Arn。
尝试了此 stackoverflow 问题 How to use Sub and GetAtt functions at the same time in CloudFormation template? 中的所有方法无济于事。
我很感激任何帮助。
Resources:
BasicParameter:
Type: AWS::SSM::Parameter
Properties:
Name: /data/config-name
Type: String
Value:
Fn::Base64:
!Sub |
{
"filter_configs": [{
"stream_name": !GetAtt tpRecordDeliveryStream.Arn,
"events": [
{
"name": "event_name1",
"stream": "streamname1"
},
{
"name": "event_name2"
}
]
}]
}
Description: Configuration for stream filters
Tags:
project: projectname
team: data
owner: owner_name
最佳答案
这是通过使用serverless-pseudo-parameters
无服务器插件解决的。 Serverless 框架还使用 ${}
占位符,它与 Cloudformation 占位符冲突。 serverless-pseudo-parameters 解决了这个问题,它允许我们用 #{}
替换这些占位符,这些占位符在 sls 部署
期间替换为云形成模板
Resources:
streamConfig:
Type: AWS::SSM::Parameter
Properties:
Name: config_name
Type: String
Value:
Fn::Base64: |
{
"filter_configs": [{
"firehose_stream_arn": "#{tpRecordDeliveryStream.Arn}",
"events": [
{
"name": "config0",
"filter1": "value1"
},
{
"name": "config1"
}
]
}]
}
Description: Configuration for stream filters
关于amazon-web-services - !GetAtt 无法与 cloudformation 中的 !Sub 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62323975/