【发布时间】:2020-08-14 06:39:14
【问题描述】:
问题
- 在不硬编码堆栈名称的情况下,在
serverless.yml文件中获取 cloudformation 堆栈输出的正确方法是什么?
步骤
我有一个 serverless.yml 文件,我在其中导入了一个 cloudformation 模板来创建一个 ElastiCache 集群。
当我尝试这样做时,我得到了这个错误:
Serverless Error ---------------------------------------
Invalid variable reference syntax for variable AWS::StackName. You can only reference env vars, options, & files. You can check our docs for more info.
在我的文件中,我想将来自 cloudformation 堆栈的 ElastiCacheAddress 输出作为环境变量公开。我正在使用serverless pseudo-parameters plugin 来获取输出:
# Here is where I try to reference the CF output value
service: hello-world
provider:
name: aws
# ...
environment:
cacheUrl: ${cf:#{AWS::StackName}.ElastiCacheAddress}
# Reference to the CF template
resources:
- '${file(./cf/cf-elasticache.yml)}'
CF 模板来自AWS Samples GitHub repository。
带有输出的sn-p在这里:
ElastiCacheAddress:
Description: ElastiCache endpoint address
Value: !If [ IsRedis, !GetAtt ElastiCacheCluster.RedisEndpoint.Address, !GetAtt ElastiCacheCluster.ConfigurationEndpoint.Address]
Export:
Name: !Sub ${AWS::StackName}-ElastiCacheAddress
【问题讨论】:
-
资源“ElastiCacheAddress”是否包含在输出部分中?您需要先声明输出部分,然后才能实际引用输出资源
-
嗨@pkarfs。是的,ElastiCacheAddress 位于 CF 模板的输出部分。这是整个文件。 github.com/aws-samples/startup-kit-templates/blob/master/…
标签: amazon-cloudformation serverless-framework