【问题标题】:How do I solve this Serverless.yml ssm dynamic path creation problem?如何解决这个 Serverless.yml ssm 动态路径创建问题?
【发布时间】:2023-02-11 07:05:08
【问题描述】:

Serverless 相当新,在创建 SSM 参数的动态路径时遇到问题......我尝试了一些想法,但我确信这真的很接近,但还不完全......

我正在尝试生成一个 ssm 路径作为自定义变量,然后用于填充 Lambda 函数的值。

这是自定义变量代码

custom
   securityGroupSsmPath:
      dev: "${self:service}/${self:custom.stage}/rds/lambdasecuritygroup"
      other: "${self:service}/${env:SHARED_INFRASTRUCTURE_ENV}/rds/lambdasecuritygroup"
   securityGroupId: ${ssm:, "${self:custom.securityGroupSsmPath.${env:SHARED_INFRASTRUCTURE_ENV}, self:custom.securityGroupSsmPath.other}"}

这是函数中引用它的地方

functions:
  someLambda:
    handler: build/handlers/someLambda/handler.handler
    timeout: 60
    memorySize: 256
    vpc:
      securityGroupIds:
        - ${self:custom.securityGroupId}

这是错误输出。好像没有解析 ssm 参数

 Serverless Error ----------------------------------------
     
Cannot resolve serverless.yml: Variables resolution errored with:
 - Cannot resolve variable at "custom.securityGroupId": Parameter name: can't be prefixed with "ssm" (case-insensitive). If formed as a path, it can consist of sub-paths divided by slash symbol; each sub-path can be formed as a mix of letters, numbers and the following 3 symbols .-_

非常感谢所有帮助,

谢谢!

山姆

【问题讨论】:

    标签: amazon-web-services serverless serverless-framework aws-ssm


    【解决方案1】:

    最后,我们尝试了多种实现,问题似乎归结为尝试检索 securityGroupId 的 ssm 值以及解析和默认其中的第二个变量。

    解决方案最终如下所示,我们从 ssm 步骤中删除了解析/默认变量。此外,我们必须删除自定义变量上的一些双引号:-

    custom
       securityGroupSsmPath:
          dev: ${self:service}/${self:custom.stage}/rds/lambdasecuritygroup
          other: ${self:service}/${env:SHARED_INFRASTRUCTURE_ENV}/rds/lambdasecuritygroup
       securityGroupId: ${self:custom.securityGroupSsmPath.${env:SHARED_INFRASTRUCTURE_ENV}, self:custom.securityGroupSsmPath.other}
    
    functions:
      someLambda:
        handler: build/handlers/someLambda/handler.handler
        timeout: 60
        memorySize: 256
        vpc:
          securityGroupIds:
            - ${ssm:/${self:custom.securityGroupId}}
    

    【讨论】:

      【解决方案2】:

      您使用的是哪个版本的无服务器?在我的版本中,我什至无法让您的解决方案发挥作用。

      【讨论】:

        猜你喜欢
        • 2020-07-27
        • 1970-01-01
        • 2019-10-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多