Created
August 18, 2020 22:06
-
-
Save singledigit/9cd1bbce1332aaad479d425641cc363f to your computer and use it in GitHub Desktop.
Creating an EventBridge rule with API Gateway as the target in AWS SAM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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