Mooncrater
Mooncrater

Reputation: 4861

How to add an event in a lambda resource that will be triggered by an API gateway in an AWS SAM template

I am trying to create an AWS SAM template which has a lambda which should be triggered by an API gateway.

The SAM template is only for the API gateway, and not for the API gateway. The API gateway will be created manually, and exists before the SAM template is deployed.

I understand that the way to do that is, under the resource I add :

Events:
 APIName:
  Type: Api
  Properties:
   Method : post
   Path : /group/user
   RestApiId:
    Ref: MyApi

An example can be looked into here.

What I don't understand is, how exactly should I be using this for my use case.

Questions that I have:

Upvotes: 0

Views: 1045

Answers (1)

David Conde
David Conde

Reputation: 4637

I'll get the questions one by one and hopefully I'll be of some help

API Name : What is to be put here? This is just an identifier for the API event you're creating. I normally use some form of description for the endpoint. Whatever you end up doing, try to have some convention or it will become hard to read (Http verb then action for instance, GetAllUsers)

How do I uniquely identify my API? : It kinda feels like you actually have two different responsibilities and thus possibly two different path names here. If sendMessage can send a message to a group or to a user then you could have sendMessageToGroup and sendMessageToUser thus making them more explicit.

Can we not link up existing API gateway? : It would appear not judging by the docs but I might be wrong on that one.

Upvotes: 1

Related Questions