HTTP Webhook Strategy - Integration with Amazon Simple Queue Service (SQS)
See the example of integration Amazon Simple Queue Service through webhooks.
Last updated
Was this helpful?
See the example of integration Amazon Simple Queue Service through webhooks.
Last updated
Was this helpful?
Thanks to HTTP webhook strategy, you can choose the event service that enables communication between Emporix and external systems. This article demonstrates how you can connect Amazon Simple Queue Service to receive events notifications from Emporix. Follow the steps to set up the connection on both sides. Adjust the actual implementation to your needs. Amazon Simple Queue Service (SQS) is a service that allows for sending, storing, and receiving messages between distributed systems. As such, you can choose it as one of the solutions to connect Emporix with some other systems in your company through the webhooks functionality.
The integration between Emporix and Amazon Simple Queue Service in this example will use Amazon Lambda that is able to receive the HTTP request, validate HMAC signature and then send the request body to the specified queue.
To create SQS, go to the AWS Management Console.
Follow the steps described in the AWS documentation .
Create a queue called webhooks
and use the default settings.
Save the URL value of your queue, which you can see in the Details section. This is later required in the Lambda code.
Create a Secret Key
that is required in the later steps to set up the connection between Lambda and SQS.
Follow the steps described in the AWS documentation
Save the Access Key Id
and Secret Key
values to provide them later in the Lambda code.
Create a Lambda function called webhookFun
.
The function uses NodeJS 16 and JavaScript.
Modify the function's code to provide necessary details in the placeholders:
Pay attention to the marked lines:
i. AWS.config
- define relevant values to the following properties: region
, accessKeyId
and secretAccessKey
.
ii. secretKey
constant - provide the secret phrase for HMAC validation. You need to specify the same value in the webhooks HTTP configuration in the later steps. Here, we defined it as password123
.
iii. when HMAC validation passes, the message body is sent with the request to the queue. Provide the QueueUrl
which points to your queue.
Deploy the modified function.
To fully prepare Amazon's part, API Gateway is required so that it triggers the Lambda through HTTP requests.
Create an API Gateway of an HTTP API
type.
a. In the Integrations section, point to your Lambda.
b. For the API name, choose webhooks
.
c. In Routes, create a POST
route.
Deploy the API Gateway
and save the url to your function. It will be needed while defining webhooks HTTP configuration on Emporix side.
Now, prepare Commerce Engine.
Configure webhooks to send the events as HTTP POST requests. Use the following curl and provide relevant information in the placeholders:
Placeholders to fill in:
tenant
- name of your production tenant
token
- your generated Emporix access token with relevant scopes
destinationUrl
- link to your API Gateway
Subscribe to a chosen event. In this example, we subscribe to the product creation event (remember to replace the values in the placeholders):
The integration is ready. To see it in action, let's create a product.
Create a product with the following curl request providing your relevant details in the placeholders:
After the product is created the event is sent. The webhook service consumes the event and sends it as HTTP request to the specified destinationUrl
, which is the API Gateway. Then, the Lambda function receives the request and sends it to Amazon Simple Queue Service (SQS).
Follow the steps described in the AWS documentation .
Find more information on how to configure HMAC validation in .
Follow the steps described in the AWS documentation .