Skip to content

Instantly share code, notes, and snippets.

@nickste
Last active December 4, 2019 19:11
Show Gist options
  • Save nickste/0423e6f9293260dee168e2800a10c07b to your computer and use it in GitHub Desktop.
Save nickste/0423e6f9293260dee168e2800a10c07b to your computer and use it in GitHub Desktop.
Builder Session Cheatsheet

Event Driven Architectures - Builder Session Cheat Sheet

Order Lambda Function

import json
import boto3

def lambda_handler(event, context):
    order = {
      "order_id": 1073459984,
      "shipping_id": "34VB5540K83",
      "category": "shoes",
      "currency": "USD",
      "price": {
        "total_price": 24.62,
        "item_price": 18.99,
        "shipping": 2.99,
        "taxes": 2.64
      },
    }
    
    client = boto3.client('events')
    response = client.put_events(
      Entries=[
        {
          'Source': 'Order System',
          'DetailType': 'Order Created',
          'Detail': json.dumps(order),
          'EventBusName': 'my-custom-event-bus'
        },
      ]
    )

SAM CLI / AWS Toolkit

Webhooks: API Gateway + EventBridge

API Gateway headers:

X-Amz-Target		'AWSEvents.PutEvents'
Content-Type		'application/x-amz-json-1.1'

API Gateway transformation:

#set($inputRoot = $input.path('$'))
{
  "Entries": [
    {
      "DetailType": $input.json('$.type'),
      "Source": "stripe",
      "EventBusName": "stripe-payments",
      "Detail": "$util.escapeJavaScript($input.json('$'))"
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment