【问题标题】:Aws-Sam Local Invoke: Layer endpoint not foundAws-Sam 本地调用:未找到层端点
【发布时间】:2020-01-26 20:16:33
【问题描述】:

我正在尝试使用 SAM 为我的 Lambda 函数设置本地开发环境。在我在配置中添加对层的引用之前,一切正常。

我按照此处的说明操作:https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-layers.html。我在我的 template.ymal 中为我的层版本添加了我的 ARN,如下所示:

# template.ymal
TestLayerFunction:
  Type: AWS::Serverless::Function
  Properties:
    FunctionName: TestLayer
    Role: arn:aws:iam::111111111111:role/ReadStreamingTable
    CodeUri: src/streaming/test-layer/
    Handler: app.handler
    Runtime: nodejs8.10
    Layers:
      - arn:aws:lambda:eu-west-1:111111111111:layer:Global:7

但是,当运行“sam local invoke”时,出现以下错误:

botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL:
 "https://lambda.eu-west-1a.amazonaws.com/2018-10-31/layers/arn%3Aaws%3Alambda%3Aeu-west-1%3A111111111111%3Alayer%3AGlobal/versions/7"

我在配置中添加层 ARN 的方式似乎正是他们在示例中的操作方式,所以我不确定是什么导致了错误。

【问题讨论】:

  • 我看到您的问题已经两个月没有得到解答,这并没有给我太大希望,因为我遇到了几乎相同的问题,尽管我正在尝试同时创建图层时间,不要使用已经部署的。我不知道这是否对您的问题有帮助,但您是否尝试过将 --layer-cache-basedir 参数与 sam invoke local 一起使用?

标签: amazon-web-services aws-lambda aws-cli aws-sam


【解决方案1】:

我知道这不完全是一个解决方案,但您不能将图层作为 SAM 文件的一部分吗?

如果您查看this article on the AWS site,他们会在同一个 yaml 文件中同时使用层和 lambda 函数,因此您最终会得到如下结果:

Resources:
    TempConversionFunction:
        Type: AWS::Serverless::Function 
        Properties:
            CodeUri: hello-world/
            Handler: app.lambdaHandler
            Layers:
              - !Ref TempConversionDepLayer
            Events:
                HelloWorld:
                    Type: Api
                    Properties:
                        Path: /{conversion}/{value}
                        Method: get

    TempConversionDepLayer:
        Type: AWS::Serverless::LayerVersion
        Properties:
            LayerName: sam-app-dependencies
            Description: Dependencies for sam app [temp-units-conv]
            ContentUri: dependencies/
            CompatibleRuntimes:
              - nodejs6.10
              - nodejs8.10
            LicenseInfo: 'MIT'
            RetentionPolicy: Retain

【讨论】:

    猜你喜欢
    • 2019-09-20
    • 2022-06-27
    • 2020-11-11
    • 2020-04-07
    • 2021-04-01
    • 2020-11-06
    • 1970-01-01
    • 1970-01-01
    • 2021-05-26
    相关资源
    最近更新 更多