Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Amazon EventBridge API Destinations demo - Cloudformation template
AWSTemplateFormatVersion: 2010-09-09
Parameters:
MailchimpMembersUrl:
Type: String
Default: https://xxx.api.mailchimp.com/3.0/lists/230948/members
MailchimpApiPassword:
Type: String
Default: REPLACEME
MSTeamsWebhookUrl:
Type: String
Default: REPLACEME
CustomerEventBusName:
Type: String
Default: i8c-magento-customers
Resources:
# EventBridge Connections
I8cMailchimpConnection:
Type: AWS::Events::Connection
Properties:
AuthorizationType: BASIC
AuthParameters:
BasicAuthParameters:
Username: "anystring"
Password: !Ref MailchimpApiPassword
I8cMsteamsConnection:
Type: AWS::Events::Connection
Properties:
AuthorizationType: API_KEY
AuthParameters:
ApiKeyAuthParameters:
ApiKeyName: no_auth_needed
ApiKeyValue: no_auth_needed
# EventBridge API Destinations
I8cMailchimpApiDestination:
Type: AWS::Events::ApiDestination
Properties:
Properties:
ConnectionArn: !GetAtt 'I8cMailchimpConnection.Arn'
InvocationEndpoint: !Ref MailchimpMembersUrl
HttpMethod: POST
InvocationRateLimitPerSecond: 10
I8cMSTeamsApiDestination:
Type: AWS::Events::ApiDestination
Properties:
ConnectionArn: !GetAtt 'I8cMsteamsConnection.Arn'
InvocationEndpoint: !Ref MSTeamsWebhookUrl
HttpMethod: POST
InvocationRateLimitPerSecond: 5
# EventBridge Delivery Rule (with 2 targets)
I8cHandleNewCustomerDeliveryRule:
Type: AWS::Events::Rule
Properties:
EventBusName: !Ref CustomerEventBusName
EventPattern:
source:
- "magento.customers"
State: "ENABLED"
Targets:
-
Id: mailchimp-target
Arn: !GetAtt I8cMailchimpApiDestination.Arn
RoleArn: !GetAtt I8cHandleNewCustomerDeliveryTargetRole.Arn
InputTransformer:
InputPathsMap:
email: $.detail.email
firstname: $.detail.firstname
lastname: $.detail.lastname
InputTemplate: >
{
"email_address": <email>,
"email_type": "html",
"status": "subscribed",
"merge_fields": {
"FNAME": <firstname>,
"LNAME": <lastname>
},
"tags": [ "demo-eventbridge"]
}
-
Id: msteams-target
Arn: !GetAtt I8cMSTeamsApiDestination.Arn
RoleArn: !GetAtt I8cHandleNewCustomerDeliveryTargetRole.Arn
InputTransformer:
InputPathsMap:
email: $.detail.email
firstname: $.detail.firstname
lastname: $.detail.lastname
createdat: $.detail.created_at
InputTemplate: >
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"themeColor": "EA6518",
"summary": "New customer on Magento",
"sections": [
{
"activityTitle": "New customer registerd on Magento 🚀 ",
"activitySubtitle": "Amazon Eventbridge demo",
"facts": [
{
"name": "Firstname",
"value": <firstname>
}, {
"name": "Lastname",
"value": <lastname>
}, {
"name": "Email",
"value": <email>
},
{
"name": "Created at",
"value": <createdat>
}],
"markdown": true
}],
"potentialAction": [
{
"@type": "OpenUri",
"name": "View in Magento",
"targets": [{
"os": "default",
"uri": "https://docs.microsoft.com/outlook/actionable-messages"
}]
}]
}
# IAM Role
I8cHandleNewCustomerDeliveryTargetRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: Allow
Principal:
Service:
- events.amazonaws.com
Action:
- 'sts:AssumeRole'
Policies:
- PolicyName: root
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: Allow
Action: 'events:InvokeApiDestination'
Resource:
- !GetAtt I8cMailchimpApiDestination.Arn
- !GetAtt I8cMSTeamsApiDestination.Arn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment