【问题标题】:Parsing integers in serverless.yml to use MemoryDB's ClusterEndpoint.Port in Environment Variable解析 serverless.yml 中的整数以在环境变量中使用 MemoryDB\'s ClusterEndpoint.Port
【发布时间】:2022-10-06 17:54:11
【问题描述】:

我正在为我的无服务器函数创建一个 MemoryDB 集群,但是 Port for the MemoryDB endpoint is an Integer,所以当我尝试设置一个环境变量以将端点 URL 传递给我的函数时,我收到一个错误

Error:
Cannot resolve serverless.yml: Variables resolution errored with:
  - Cannot resolve variable at \"provider.environment.MEMORYDB_ENDPOINT\": String value consist of variable which resolve with non-string value

示例 serverless.yml 文件:

provider:
  name: aws
  # [...]
  environment:
    MEMORYDB_PORT: ${self:custom.MEMORYDB_PORT}
# [...]
custom:
  MEMORYDB_PORT: !GetAtt MemoryDB.ClusterEndpoint.Port

我尝试过使用 Fn::Join、Fn::Sub (插件)和其他方法,但它们都希望字符串作为参数。

我不打算使用自定义端口,所以我总是可以假设默认值,但是我觉得我在这里遗漏了一些东西。

有没有办法以某种方式解析无服务器/云格式中的整数?或者至少将该端口转换为字符串?

    标签: amazon-cloudformation serverless-framework


    【解决方案1】:

    您可以尝试使用自定义插件:https://www.serverless.com/framework/docs/guides/plugins/custom-variables

    它看起来很相似

        export class MaxBatchingWindowIntParser {
          public configurationVariablesSources: object;
    
          public constructor() {
            this.configurationVariablesSources = {
              parseValue: {
               resolve({ address }) {
                 return {
                   value: Number.parseInt(address, 10),
                 };
                },
               },
              };
             }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-27
      • 2010-10-29
      • 1970-01-01
      • 2020-09-11
      • 1970-01-01
      • 1970-01-01
      • 2017-10-10
      • 2021-04-01
      相关资源
      最近更新 更多