AWS › AWS Serverless Application Model (SAM)
How does SAM support defining event sources, such as API Gateway or S3 triggers, directly within a function's configuration?
IntermediateAnswer
SAM lets you define event sources as a property directly on a serverless function resource, such as specifying an Api event type to automatically create an API Gateway endpoint that triggers the function, or an S3 event type to trigger the function whenever a new object is uploaded to a specific bucket, automatically wiring up all of the necessary underlying permissions and event source configuration without you needing to configure each connected service separately.
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
Events:
ApiEvent:
Type: Api
Properties:
Path: /orders
Method: postReal-world example A developer defines a Lambda function in their SAM template with an Api event source pointing to a specific path and HTTP method, and SAM automatically creates and wires up the corresponding API Gateway resource along with all necessary permissions.