Created
May 2, 2021 17:16
-
-
Save samuelcastle/397369454cf312abc3a660efed22d278 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: 2010-09-09 | |
Description: >- | |
i8c-awsintegration-demo | |
Transform: | |
- AWS::Serverless-2016-10-31 | |
Parameters: | |
# Eventbus Configuration | |
EventbusName: | |
Type: String | |
Default: i8c-wickey-orders | |
# Salesforce Configuration | |
SalesforceOauthUrl: | |
Type: String | |
Default: REPLACEME | |
SalesforceOauthClientId: | |
Type: String | |
Default: REPLACEME | |
SalesforceOauthClientSecret: | |
Type: String | |
Default: REPLACEME | |
SalesforceUsername: | |
Type: String | |
Default: REPLACEME | |
SalesforcePassword: | |
Type: String | |
Default: REPLACEME | |
SalesforceContactsUrl: | |
Type: String | |
Default: REPLACEME | |
Resources: | |
I8cSalesforceConnection: | |
Type: AWS::Events::Connection | |
Properties: | |
AuthorizationType: OAUTH_CLIENT_CREDENTIALS | |
AuthParameters: | |
OAuthParameters: | |
AuthorizationEndpoint: !Ref SalesforceOauthUrl | |
ClientParameters: | |
ClientID: !Ref SalesforceOauthClientId | |
ClientSecret: !Ref SalesforceOauthClientSecret | |
HttpMethod: POST | |
OAuthHttpParameters: | |
BodyParameters: | |
- IsValueSecret: false | |
Key: grant_type | |
Value: password | |
- IsValueSecret: false | |
Key: username | |
Value: !Ref SalesforceUsername | |
- IsValueSecret: true | |
Key: password | |
Value: !Ref SalesforcePassword | |
# EventBridge API Destinations | |
I8cSalesforceContactsApiDestination: | |
Type: AWS::Events::ApiDestination | |
Properties: | |
ConnectionArn: !GetAtt 'I8cSalesforceConnection.Arn' | |
InvocationEndpoint: !Ref SalesforceContactsUrl | |
HttpMethod: PATCH | |
InvocationRateLimitPerSecond: 5 | |
# EventBridge Delivery Rule | |
I8cHandleNewCustomerDeliveryRule: | |
Type: AWS::Events::Rule | |
Properties: | |
EventBusName: !Ref EventbusName | |
EventPattern: | |
source: | |
- "magento.customers" | |
State: "ENABLED" | |
Targets: | |
- | |
Id: salesforce-target | |
Arn: !GetAtt I8cSalesforceContactsApiDestination.Arn | |
RoleArn: !GetAtt I8cHandleNewCustomerDeliveryTargetRole.Arn | |
HttpParameters: | |
PathParameterValues: | |
- '$.detail.id' # This fills in customer id of Magento in Salesforce contact url | |
InputTransformer: | |
InputPathsMap: | |
email: $.detail.email | |
firstname: $.detail.firstname | |
lastname: $.detail.lastname | |
magentoId: $.detail.id | |
InputTemplate: > | |
{ | |
"LastName": <lastname>, | |
"FirstName": <firstname>, | |
"Email": <email>, | |
"Source_System__c": "Magento" | |
} | |
RetryPolicy: | |
MaximumRetryAttempts: 20 | |
DeadLetterConfig: | |
Arn: !GetAtt DLQSalesforceIntegration.Arn | |
# 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 I8cSalesforceContactsApiDestination.Arn | |
# DLQ - Salesforce integration | |
DLQSalesforceIntegration: | |
Type: AWS::SQS::Queue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment