使用无服务器将lambda函数部署到LocalStack时无法使用httpApi

时间:2020-07-09 11:51:11

标签: aws-api-gateway serverless localstack

我对无服务器整体还很陌生,并尝试在我的机器上设置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'>

1 个答案:

答案 0 :(得分:0)

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

AWS docs 请注意,HTTP API 使用 API 网关的 -v2 版本,根据 localstack repo 的说法,这仅在专业版中受支持。