How to Integrate Your Headless Commerce Retail Store With Commercetools—Part 2
In our previous post How to Integrate Your Headless Commerce Retail Store With Commercetools—Part 1, we walked you through the process to integrate an ecommerce store front end with a backend retail microservice from the commercetools solution using commercetools’s APIs.
Built in the Amazon Web Services (AWS) cloud, commercetools provides a set of flexible REST and GraphQL APIs designed to meet the demanding needs of modern ecommerce solutions. The APIs create an interface for programmatic access to data stored on this solution and associated functionality. commercetools, an AWS Partner, offers a production-ready commerce solution that retailers can use to build high-quality, scalable, modern ecommerce architectures.
In part 2 of this blog series, we will show you how to use Amazon EventBridge—a serverless event bus that makes it easier to build event-driven applications at scale across AWS, existing systems, or software-as-a-service (SaaS) applications—to react to certain events that are generated in the commercetools’s solution. We’ll walk you through the process to implement a common customer engagement use case: sending an email campaign to announce a new product to customers.
The commercetools solution generates messages when a change or an action occurs on a resource, such as an order or a product. You can create notifications about new messages using the message queue service of your choice, such as Amazon Simple Queue Service (Amazon SQS), a fully managed message queuing service that transmits data across systems using messages, or Amazon EventBridge.
Because Amazon EventBridge provides an easy way to filter and route messages based on content, commercetools users can use the service to create scalable, dynamic event pipelines at low operational costs. Some other common use cases are:
- Product review moderation and customer engagement—upon receiving a product review, you can use Amazon Comprehend, a natural-language processing (NLP) service that uses machine learning (ML) to uncover valuable insights and connections in text, to determine if the review is negative or offensive, and in the case of unfavorable sentiment, you can proactively contact the customer to address the situation.
- Customer engagement—when a product is discounted, you can contact customers who previously viewed or bought the same or similar products and encourage them to come back to your store.
- Order fulfilment—once an order is placed, you want to ship the item(s) from the closest facility to the customer. See this tutorial to learn more about how to implement this solution.
Process to implement new product email announcement use case
For this example, the flow is as follows:
- A store administrator creates and publishes a new product on the web front end. An API calls the commercetools’s APIs to create the new product on the backend.
- commercetools generates the “ProductPublishedMessage” and delivers it to Amazon EventBridge.
- Then, Amazon EventBridge routes the message to a target in AWS Lambda, a serverless, event-driven compute service that lets you run code for virtually any type of application or backend service without provisioning or managing servers.
- The AWS Lambda function calls the API on Amazon Pinpoint, a multichannel marketing communication service, through the AWS SDK to create a new email campaign and send a message to a segment of customers announcing the new product.
First, you need to build a customer segment in Amazon Pinpoint for the email campaign. In Amazon Pinpoint, a segment is a group of customers that share certain attributes. For example, you can create segments for all customers who visited your store in the past year or all customers who have placed an order. You should follow these instructions to build segments to target different sets of customers.
Next, you need to create the target AWS Lambda function to which Amazon EventBridge will route the
ProductPublishedMessage. You can use the sample code for your AWS Lambda function. Be sure to use the segment that you created earlier and customize the message so that it’s appropriate for the target customer set. Please note: to send email messages through Amazon Pinpoint, you need to initiate the email channel and verify one sender email address.
From the Amazon EventBridge management console, configure a new partner event source integration for commercetools.
To complete the commercetools-Amazon EventBridge integration, you need to create a subscription with commercetools Subscription API, as shown below.
The payload you need to send is similar to the following:
Back in the Amazon EventBridge management console, choose “Partner event sources” in the navigation pane. Select the button next to the partner event source with the same name as the one that you specified in your payload, and then choose “Associate with event bus.”
You’ll see the status of the event source changed from “pending” to “active,” and the name of the event bus will update to match the partner event source name.
Next, you need to configure a rule to match the commercetools events by following these steps. In the “Define pattern” section, do the following:
- Choose “Event pattern.”
- Choose “Predefined pattern by service.”
- For “Service provider,” choose “Service partners.”
- For “Service name,” choose “commercetools.”
- Customize the event pattern to match only the “Product Published” Choose “Edit,” make your changes, and then “Save.”
For “Service event bus,” be sure to select the event bus that’s associated with the partner event source that you created earlier.
As a target for this rule, select the Amazon Lambda function that you created earlier. Choose “Create” to create the rule.
Finally, you need to test the solution. From the commercetools Merchant Center, create and publish a new product. Once you’ve created a new product, you can verify the status of the campaign from the Amazon Pinpoint management console.
Get started today
We hope that you found this blog to be helpful. If you want to learn more about event-drive architectures with Amazon EventBridge, be sure to check out this AWS workshop.
If you want to discuss how a headless commerce architecture can benefit your retail business or you need help creating event-driven email campaigns with Amazon Pinpoint and commercetools, contact your AWS account team or visit Retail on AWS today to get started.
AWS Partner Spotlight
commercetools is a leading commerce platform built on modern MACH principles (microservice-based, API-first, cloud-native, headless), allowing retailers to work with, not around, their commerce solution to tailor experiences to the exact needs of the business and its customers.
Learn more about commercetools here.