Skip to content

Instantly share code, notes, and snippets.

@nickste
Created October 2, 2019 21:44
Show Gist options
  • Save nickste/a6ef6c99c29ac74fbac70e620918dd23 to your computer and use it in GitHub Desktop.
Save nickste/a6ef6c99c29ac74fbac70e620918dd23 to your computer and use it in GitHub Desktop.

EventBridge Deep Dive - Webinar Cheat Sheet

This cheat sheet was created as a reference for some of the code and commands used in the Amazon EventBridge Deep Dive webinar.

Rules

Testing a Rule Pattern:

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

Targets

Example Input Transformers:

Input map:

{"orderNumber":"$.detail.orderNumber","price":"$.detail.price","productId":"$.detail.productId"}

Input template:

"{\"orderNumber\": \"<orderNumber>\", \"productId\": \"<productId>\", \"price\": \"<price>\"}"

Connecting API Gateway to EventBridge

Integration request configuration:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment