AWS SAM-模板没有任何与Lambda函数连接的API

Kri*_*ngs 6 amazon-web-services aws-serverless

因此,我正在尝试将现有的spring boot应用程序转换为AWS lambda并使用SAM。

我正在尝试使用aws-sam-cli在本地尝试我的lambda,但是通过我的SAM设置我得到了: Template does not have any APIs connected to Lambda functions

当我做: sam local start-api

我的template.yml

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: foo
Resources:
  MailFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: bar.LambdaHandler::handleRequest
      Runtime: java8
      CodeUri: target/foo-bar-1.0.jar
      Timeout: 300
      MemorySize: 1024
      Events:
        Timer:
          Type: Schedule
          Properties:
            Schedule: rate(1 day)
Run Code Online (Sandbox Code Playgroud)

知道我在做什么错吗?据我从https://blog.couchbase.com/aws-serverless-lambda-scheduled-events-tweets-couchbase/ + https://docs.aws.amazon.com/lambda/latest所知,它看起来是正确的/dg/tutorial-scheduled-events-schedule-expressions.html

H6.*_*H6. 12

您没有向您的函数添加任何 API 网关事件。并start-api生成一个本地 API 网关。

您需要至少Api向您的Events部分添加一个事件。

Events:
  [...]
  Api:
    Type: Api
    Properties:
      Path: /myresource
      Method: get
Run Code Online (Sandbox Code Playgroud)

如果您只是有一个Schedule事件,请尝试使用generate-event来创建这样的事件。

sam local generate-event schedule ...

并调用函数,例如sam local invoke function-name -e event_file.json


dz9*_*902 7

对于 Google 员工:

  • 检查是否有EventType: Api
  • 还要检查您是否已运行sam build非常重要
  • 使用--debug标志,这样你就会知道发生了什么

截至 2020/7/13,Type: HttpApi不适用于sam local start-api. 见问题