yaml - 无服务器变量插值 env:VAR 使用 Fn::GetAtt 回退

标签 yaml aws-cloudformation serverless-framework

当使用无服务器框架部署我的应用程序时,我的临时/生产环境使用作为应用程序所需资源的一部分启动的相应 ElasticCache 实例,并且端点设置为环境变量。

  environment:
    REDIS_URL:
      Fn::Join:
        - ''
        - - 'redis://'
          - Fn::GetAtt: [ElasticCacheCluster, RedisEndpoint.Address]

上面的实现工作正常,但是当使用serverless-offline时,这显然没有获得真正的端点,并且REDIS_URL最终为redis://[object Object].

我想要做的是使用env:REDIS_URL(如果存在),如果没有,则使用上面的 Fn::GetAtt 进行设置。

鉴于正常的后备语法是 ${env:REDIS_URL, Fallback} 我认为我能够使用上述 Fn:GetAtt 的某种形式,但我似乎无法得到语法工作。

  environment:
    REDIS_URL: ${env:REDIS_URL,
      { Fn::Join:
        - ''
        - - 'redis://'
          - Fn::GetAtt: [ElasticCacheCluster, RedisEndpoint.Address] }
    }

如何做到这一点?

最佳答案

在其他地方计算 Fn:Join,然后在环境配置中将其引用为后备似乎可行。

provider:
  environment:
    REDIS_URL: ${env:REDIS_URL, self:custom.REDIS_URL}
custom:
  REDIS_URL:
    Fn::Join:
      - ''
      - - 'redis://'
        - Fn::GetAtt: [ElasticCacheCluster, RedisEndpoint.Address]

关于yaml - 无服务器变量插值 env:VAR 使用 Fn::GetAtt 回退,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64350072/

相关文章:

go - 如何使用任意键解析 YAML

integration-testing - 如果 CodeBuild 失败,则删除 CloudFormation 堆栈

javascript - 自定义域在带有 serverless-next.js 的 aws 中不起作用?

python - Oauth2 到 aws lambda 上的 google people api

node.js - 基于 Swagger YAML 验证 Express 请求

python - 如何防止在 YAML 中重新定义 key ?

ansible - 检查其中一个文件是否存在于ansible中

amazon-web-services - AWS CodePipeline 错误 : Cross-account pass role is not allowed

amazon-web-services - 将资源添加到现有的 CloudFormation 堆栈

amazon-web-services - 更新 Cognito 用户池/AWS 资源