rooscous
rooscous

Reputation: 511

SAM Lambda event with an explicit API as the event source

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?

Upvotes: 2

Views: 624

Answers (1)

rooscous
rooscous

Reputation: 511

I needed to add the RestApiId under the event definition like so:

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

Upvotes: 1

Related Questions