2

I am trying to set up an event on my lambda function in my SAM template, but I want the event source to be an explicit API endpoint.

The documentation shows an event with an implicit API as an event source:

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

This would be the explicit API definition:

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

How do I explicitly set the event source to be MyApi?

4

1 回答 1

1

我需要RestApiId像这样在事件定义下添加:

Events:
    GetResource:
      Type: Api
      Properties:
        RestApiId: !Ref MyApi
        Path: /resource/{resourceId}
        Method: get
于 2017-09-26T15:51:24.563 回答