AWS Messaging & Targeting Blog
Automate workflows with WhatsApp using AWS End User Messaging Social
In today’s world, WhatsApp has become a widely used communication app, with over 2.7 billion users globally. As a business owner, you likely have customers who use WhatsApp regularly. This presents an opportunity to use WhatsApp as an additional channel to increase your reach and engage with your customers more effectively. WhatsApp messaging need not be limited to one-on-one interactions with your customers. You can also use it to automate some of your business workflows. These workflows can be part of your existing workloads running on AWS, or you can build new automations using AWS services.
AWS End User Messaging Social natively links your WhatsApp Business Account (WABA) and your AWS account. This helps simplify building integrations between your customer’s WhatsApp messenger app and your workloads running on AWS. Additionally, it also provides unified billing experience within AWS.
This post walks through a solution to establish this integration and automate your business workflows using WhatsApp and AWS End User Messaging Social.
Overview of solution
The solution uses AWS End User Messaging Social to integrate your workload deployed on AWS with your Meta business portfolio. This allows you to receive WhatsApp messages that your end customers send, directly in your AWS environment. An incoming WhatsApp message that AWS End User Messaging Social receives triggers an Amazon Simple Notification Service (SNS) notification, which then activates an AWS Lambda function. This Lambda function processes the request and then sends a WhatsApp message as a response to the user. You can build complex business workflows and automated WhatsApp marketing expanding this solution.
![Figure 1: Solution Architecture Solution architecture of the post shows customer sending a WhatsApp message to a workload that is hosted on AWS. AWS End User Messaging Social receives the WhatsApp message. It then forwards the message to an SNS topic. This triggers a Lambda function. The Lambda function then sends a WhatsApp reply back to the customer’s mobile phone through End User Messaging Social](https://d2908q01vomqb2.cloudfront.net/632667547e7cd3e0466547863e1207a8c0c0c549/2025/01/22/012025_Solution_Architecture.png)
Figure 1: Solution Architecture
IMPORTANT: Note that any WhatsApp user can send a message to your WABA number and trigger the workflow. To avoid incurring ongoing charges, complete the steps in the “Cleaning up” section.
Prerequisites
Before starting this walkthrough, ensure you have:
- An AWS account
- A Meta business portfolio. Create one by following these instructions
- A phone number to create a WABA
- A phone with WhatsApp Messenger app installed to test the solution. Note that the mobile app uses a different phone number than the one that is associated with your WABA.
- AWS CLI installed and configured to access to your AWS account
- Serverless Application Model CLI to deploy the sample application
- node.js >= 22.x
Implementing the solution
Step 1: Create an SNS topic
- Navigate to the SNS page.
- Use the AWS region where you plan to use AWS End User Messaging Social.
- Select “Standard” as the topic “Type”
- Enter “WhatsAppIncomingMessages” as the “Name” of the topic
- Click on the “Create topic” button.
- In the topics details that appear, note the “ARN” of the topic
Step 2: Add WABA to AWS End User Messaging
- Navigate to the WABA page.
- Click on the “Add WhatsApp phone number” button
- Click on “Launch Facebook portal” to connect your AWS account and your Meta business portfolio.
- Follow the instructions in the Facebook pop-up to complete the registration. Below are screenshots of the key steps in the process:
![Figure 2: Connect AWS and Meta Business Portfolio Screenshot of the steps you need to follow to connect your AWS account and your Meta business portfolio.](https://d2908q01vomqb2.cloudfront.net/632667547e7cd3e0466547863e1207a8c0c0c549/2025/01/22/012025_Registration_Steps_all.png)
Figure 2: Connect AWS and Meta Business Portfolio
- After the Facebook signup popup closes, you will see this “Link established” message on your AWS console. Enter the ARN of the SNS topic created in Step 1 in the “Message and event destination” section.
![Figure 3: Successfully linked WABA and AWS account Screenshot of the AWS console that shows established connection between AWS and WABA account and the SNS topic](https://d2908q01vomqb2.cloudfront.net/632667547e7cd3e0466547863e1207a8c0c0c549/2025/01/22/012025_WABA_Phone_Setup_Step.png)
Figure 3: Successfully linked WABA and AWS account
- Click “Add phone number” to complete linking your WhatsApp business account with your AWS account.
- Navigate to the WABA page and verify that the added account is in “Active” status.
- Click on the Business account ID you added to navigate to the details page.
- From the “Phone Numbers” section, note the “Phone number ID” of the number that you added.
Step 3: Deploy the Lambda function to handle customer WhatsApp messages
- Clone the example repository and deploy the Lambda function by following the steps below:
$ git clone https://github.com/aws-samples/aws-end-user-messaging-social-automation.git $ cd aws-end-user-messaging-social-automation/
- Build the project by running this command:
$ sam build
- Deploy the application by running the command below and follow the prompts:
$ sam deploy --guided ... # Enter the details for questions asked Stack Name [sam-app]: EndUserMessagingWhatsApp AWS Region [us-east-1]: <AWS region where you have created the WABA account> Parameter SNSTopicArn []: <ARN of the SNS topic created in Step 1> Parameter PhoneNumberID []: <Phone number ID from Step 2>
Accept the defaults of the rest of the questions to complete the deployment. This will create a Lambda function that is triggered when a WhatsApp message is sent to your WABA number
Step 4: Testing the solution
- From a phone that has WhatsApp installed, send this message to your WABA phone number
Hello
- Validate that you see the following in response to the previous message:
- Blue check mark, indicating the message has been received and read
- A 👋 reaction to your message
- A reply message saying “Hello {profile name}, how can we help you?”
- A list of options to choose from
- Select one of the options
- You will receive a static message pointing you to find more information about the AWS End User Messaging service in the documentation page. The interaction will look like the picture below:
![Figure 4: End user’s WhatsApp interaction with the business Screenshot of the end user’s WhatsApp interaction. User sends a Hello! Message, to which the business responds with 2 options to choose from. Customer selects check order status option, to which the business responds with a link to documentation about End user messaging service.](https://d2908q01vomqb2.cloudfront.net/632667547e7cd3e0466547863e1207a8c0c0c549/2025/01/22/012025_WhatsApp_Message_Interaction.png)
Figure 4: End user’s WhatsApp interaction with the business
Troubleshooting
Access the logs of your lambda function by navigating to the CloudWatch logs page and searching for “WhatsAppMessageHandler” in the search box. Select the log group of your Lambda function and click on the log stream corresponding to the time you ran the test. The Lambda function logs information when a message is received and processed. However, Lambda’s received SNS events and extracted user messages are deliberately excluded from CloudWatch logs. The event contains information such as sender’s phone number and WhatsApp profile name that can be classified as sensitive by your business. Check your organization’s data handling policies before logging this information. Find more information on the message structure of the different message types in Meta developer documentation.
You can also use AWS CLI to send messages to customers. You can send messages of “text” type if your customer has already initiated a conversation with you. Run the command below to send a reply to a WhatsApp message:
aws socialmessaging send-whatsapp-message \ --cli-binary-format raw-in-base64-out \ --message '{"messaging_product": "whatsapp", "to": "+15554567890", "text": { "preview_url": false, "body": "Hello! How can we help you?"}}' \ --origination-phone-number-id phone-number-id-beac123456789abcdefgh \ --meta-api-version v20.0
Note that you can only send messages of type “text” to customer if they have started a conversation with you and it has been less than 24 hours since the last time they messaged you. Use templated messages to start conversations with your customers, for example, to send an OTP (one-time password) or marketing messages. Meta needs to approve message templates before you can send them to customers.
Monitoring
AWS End User Messaging Social can publish data related to cost of using the service to CloudWatch metrics. To enable this, enter the command below to create a IAM service linked role called “AWSServiceRoleForSocialMessaging”:
aws iam create-service-linked-role --aws-service-name social-messaging.amazonaws.com
You can monitor AWS End User Messaging Social using CloudWatch to view metrics:
- WhatsAppMessageFeeCount
- WhatsAppConversationFeeCount
You can get also get notified when a specific threshold is reached by setting up a CloudWatch alarm on these metrics. This can help you keep track of costs associated with AWS End User Messaging Social.
Cleaning up
Note that any WhatsApp user can send a message to your WABA number and trigger the workflow. To avoid incurring ongoing charges, complete the following cleanup steps:
- To delete the Lambda function and the associated resources, run the following command:
sam delete
- To delete the AWS End User Messaging Social resources, navigate to the WABA page. Select the Business account ID of your WABA and click on the “Unlink” button.
Conclusion
This post shows how you can simplify the integration between WhatsApp and your workloads running on AWS, allowing you to automate interactions with your end customers. It shows how you can trigger a Lambda function from a WhatsApp message initiated by your end customer. You can extend this solution to build more complex workflows, for example triggering an AWS Step Functions , invoking your container based workloads running on AWS among others.
For more information, see the following resources: