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: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html
- AWS Toolkit (IntelliJ): https://aws.amazon.com/intellij/
- AWS Toolkit (VS Code): https://aws.amazon.com/visualstudiocode/
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('$'))"
}
]
}