Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Creating an EventBridge rule with API Gateway as the target in AWS SAM
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Event Bridge -> API Gateway
Resources:
RestApiGateway:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
# Function here for the route and testing
RestApiFunction:
Type: AWS::Serverless::Function
Properties:
InlineCode: |
exports.handler = async (event) => {
console.log(JSON.stringify(event))
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};
Handler: index.handler
Runtime: nodejs12.x
Events:
FetchRest:
Type: Api
Properties:
RestApiId: !Ref RestApiGateway
Method: POST
Path: /
### API Gateway ARNs: https://docs.aws.amazon.com/apigateway/latest/developerguide/arn-format-reference.html
### More on targets: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html
### More on PutTargets: https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_PutTargets.html
MyBusRule:
Type: AWS::Events::Rule
Properties:
Description: Event bridge rule to trigger REST API
EventPattern: { "source": [ "myBusEvent" ] }
Targets:
- Arn: !Sub arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${RestApiGateway}/Prod/POST/*
Id: MyRestTarget
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment