This cheat sheet was created as a reference for some of the code and commands used in the Amazon EventBridge Deep Dive webinar.
aws events test-event-pattern --event-pattern "{\"source\": [\"Order Service\"],\"detail-type\":[\"New Order\"]}" --event '{"id": "e00c66cb-fe7a-4fcc-81ad-58eb60f5d96b", "detail-type": "New Order", "source": "Order Service", "account": "123456789012", "time": "2016-01-10T01:29:23Z", "region": "us-east-1", "detail": "{\"orderNumber\": \"123456\",\"productId\": \"shoe_007\",\"price\": 130,\"customer\": {\"name\": \"Nick Smit\",\"customerId\": \"987654321\",\"address\": \"2121 7th Ave, Seattle, WA 98121\"}}\",\"EventBusName\": \"orders\"}"}' --profile webinar
Input map:
{"orderNumber":"$.detail.orderNumber","price":"$.detail.price","productId":"$.detail.productId"}
Input template:
"{\"orderNumber\": \"<orderNumber>\", \"productId\": \"<productId>\", \"price\": \"<price>\"}"
To send events from API Gateway to EventBridge (referred to as CloudWatch Events in API Gateway console), the following needs to be configured:
AWS Service: CloudWatch Events
Action: PutEvents
Execution Role: (provide an IAM role that has full EventBridge permissions)
Then set the following HTTP headers in the integration request configuration (be sure to include the single quotes):
X-Amz-Target 'AWSEvents.PutEvents'
Content-Type 'application/x-amz-json-1.1'
Finally, in the Mapping Templates section, add a content type for application/json
and set the template to the following:
#set($inputRoot = $input.path('$'))
{
"Entries": [
{
"DetailType": $input.json('$.type'),
"Source": "stripe",
"EventBusName": "stripe-payments",
"Detail": "$util.escapeJavaScript($input.json('$'))"
}
]
}
The above example is for Stripe webhooks. You can update the DetailType
field to reference any other field in your incoming HTTP request's json payload.