首页 文章

具有显式API作为事件源的SAM Lambda事件

提问于
浏览
2

我试图在我的SAM模板中设置我的lambda函数的事件,但我希望事件源是一个显式的API endpoints .

该文档显示了一个带有隐式API作为事件源的事件:

GetFunction:
  Type: AWS::Serverless::Function
  Properties:
    Handler: index.get
    Runtime: nodejs6.10
    CodeUri: s3://bucket/api_backend.zip
    Policies: AmazonDynamoDBReadOnlyAccess
    Environment:
      Variables:
        TABLE_NAME: !Ref Table
    Events:
      GetResource:
        Type: Api
        Properties:
          Path: /resource/{resourceId}
          Method: get

这将是显式的API定义:

Resources:
  MyApi: 
    Type: AWS::Serverless::Api
    Properties:
      StageName: prod
      DefinitionUri: swagger.yml

如何将事件源明确设置为MyApi?

1 回答

  • 2

    我需要在事件定义下添加 RestApiId ,如下所示:

    Events:
        GetResource:
          Type: Api
          Properties:
            RestApiId: !Ref MyApi
            Path: /resource/{resourceId}
            Method: get
    

相关问题