【问题标题】:Cant use httpApi while deploying lambda functions to LocalStack using serverless使用无服务器将 lambda 函数部署到 LocalStack 时无法使用 httpApi
【发布时间】:2021-01-13 23:00:43
【问题描述】:

我对 serverless 整体来说还很陌生,并试图在我的机器上设置 LocalStack。 我已成功将一个测试 lambda 函数部署到 LocalStack,但目前面临 API 网关问题。

使用以下配置进行部署时,一切正常,我能够使用 http 正确访问 lambda 函数,并且在部署结束时像往常一样打印生成的端点:

service: localtest

frameworkVersion: ">=1.74.1"

provider:
  name: aws
  runtime: nodejs12.x
  stage: local

plugins:
  - serverless-localstack

custom:
  localstack:
    stages:
      - local
    host: http://localhost  
    autostart: true 
    endpoints:
      S3: http://localhost:4566
      DynamoDB: http://localhost:4566
      CloudFormation: http://localhost:4566
      Elasticsearch: http://localhost:4566
      ES: http://localhost:4566
      SNS: http://localhost:4566
      SQS: http://localhost:4566
      Lambda: http://localhost:4566
      Kinesis: http://localhost:4566
    lambda:
      mountCode: True
    docker:
      sudo: False

functions:
  hello:
    handler: handler.hello
    events:
      - http:
          method: get
          path: /

serverless deploy 的结果输出:

Service Information
service: localtest
stage: local
region: us-east-1
stack: localtest-local
resources: 10
api keys:
  None
endpoints:
  http://localhost:4567/restapis/720w6afoyh/local/_user_request_
functions:
  hello: localtest-local-hello
layers:
  None

但是,当尝试在事件中使用 httpApi 实现时

 - httpApi:
          method: get
          path: /

我从 localstack 收到了几个错误,该函数似乎已部署但不输出路径。

来自 LocalStack 的错误日志:

2020-07-09T11:39:50:WARNING:moto: No Moto CloudFormation support for AWS::ApiGatewayV2::Integration
2020-07-09T11:39:50:WARNING:moto: No Moto CloudFormation support for AWS::ApiGatewayV2::Stage
2020-07-09T11:39:50:WARNING:moto: No Moto CloudFormation support for AWS::ApiGatewayV2::Api
2020-07-09T11:39:50:WARNING:moto: No Moto CloudFormation support for AWS::ApiGatewayV2::Route
2020-07-09T11:39:50:WARNING:moto: No Moto CloudFormation support for AWS::ApiGatewayV2::Api
2020-07-09T11:39:55:WARNING:localstack.services.cloudformation.cloudformation_starter: Unable to resolve "Ref" attribute for: {'Ref': 'HelloLambdaVersionFjNrIW0CS0DGT44Agi2AjgeDtzxVf8vf0JBR6XRariM'} - HelloLambdaVersionFjNrIW0CS0DGT44Agi2AjgeDtzxVf8vf0JBR6XRariM - <class 'moto.awslambda.models.LambdaVersion'>

【问题讨论】:

    标签: aws-api-gateway serverless localstack


    【解决方案1】:

    我遇到了同样的问题。这显然仅在 pro 版本的 localstack 中受支持,而不是免费版本。

    AWS docs 请注意,HTTP API 使用 API Gateway 的 -v2 版本,根据localstack repo,只有专业版才支持此功能。

    【讨论】:

      猜你喜欢
      • 2021-08-22
      • 1970-01-01
      • 2021-10-07
      • 1970-01-01
      • 2019-03-02
      • 1970-01-01
      • 2020-06-07
      • 2023-01-20
      • 2021-01-07
      相关资源
      最近更新 更多