Create an EventBridge rule that invokes a Lambda function
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Serverless patterns - EventBridge to Lambda (uksb-1tthgi812) (tag:eventbridge-lambda)
Resources:
# Define the consumer Lambda function and EventBridge rule
ConsumerFunction:
Type: AWS::Serverless::Function
Description: Invoked by EventBridge rule
Properties:
CodeUri: src/
Handler: app.handler
Runtime: nodejs20.x
Timeout: 3
Events:
Trigger:
Type: EventBridgeRule
Properties:
Pattern:
source:
- custom.myApp
detail-type:
- transaction
detail:
location:
- "prefix": "EUR-"
Outputs:
ConsumerFunction:
Description: ConsumerFunction function name
Value: !Ref ConsumerFunction
Visit the GitHub repo for this pattern.
git clone https://github.com/aws-samples/serverless-patterns/ cd serverless-patterns/eventbridge-lambda
sam deploy --guided
aws events put-events --entries file://event.json
.sam logs -n ENTER_YOUR_CONSUMER_FUNCTION_NAME
.sam delete --stack-name STACK_NAME
.aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"