WhatsApp dominates the messaging world with 2.3 billion active users and leads in over 100 countries. Did you know that?
AWS launched End User Messaging Social to help developers send WhatsApp messages to their end users. This integration lets developers build budget-friendly chatbots and manage AWS resources through WhatsApp messages. The results speak for themselves – Duolingo’s success story shows a 12% boost in verification rates and an impressive 87% cost reduction by combining SMS fallback with WhatsApp messaging.
Let’s walk through the AWS WhatsApp API integration using Amazon Pinpoint’s multichannel platform. The platform supports six different channels including SMS, email, and push notifications. You’ll learn everything from initial setup to testing your WhatsApp messaging system.
Does WhatsApp use AWS?
AWS and WhatsApp have a complex relationship. WhatsApp doesn’t run solely on AWS infrastructure, but AWS provides resilient services built for WhatsApp Business integration.
AWS End User Messaging Social lets developers connect WhatsApp Business Accounts directly to their AWS environments. This native integration makes it easier to build connections between customer WhatsApp interactions and AWS workloads.
The architecture works like this: AWS End User Messaging Social gets a WhatsApp message that triggers an Amazon Simple Notification Service (SNS) notification. This activates an AWS Lambda function. The function processes the request and sends the response back to users through WhatsApp. This setup powers complex business workflows and automated WhatsApp marketing campaigns.
AWS gives developers two ways to integrate WhatsApp:
- Direct integration – Set up a new WhatsApp Business Account through AWS’s self-guided onboarding
- Existing account connection – Connect your current WhatsApp Business Account to AWS End User Messaging
These setups work for both sending and receiving messages:
- Outbound messaging: Amazon Pinpoint’s custom channel employs an AWS Lambda function that makes API calls to WhatsApp with the access token, customer’s mobile number, and message template
- Inbound messaging: Amazon API Gateway acts as the callback URL while AWS Lambda handles authorization and messages
AWS End User Messaging Social sends cost metrics to CloudWatch. This helps track key data points like WhatsAppMessageFeeCount and WhatsAppConversationFeeCount.
The service runs in seven AWS regions, including US East (N. Virginia), US West (Oregon), Europe (London), and Asia Pacific (Singapore). WhatsApp Business Accounts need verification, which takes up to two weeks.
Note that WhatsApp has its own terms, policies, and fees beyond AWS services before you start any integration project.
Set Up WhatsApp Business API and AWS prerequisites
The WhatsApp Business API integration with AWS needs some groundwork before you start. You should create accounts and get the right credentials first.
Create a Meta Developer account and app
Log into your Facebook account to access the Meta for Developers platform. Here’s what you need to do:
- Click “Create App” in the dashboard
- Select “Business” as the app type
- Enter a display name and contact email
- Choose to attach a Business Account or create a new one
- After creation, go to WhatsApp section and click “Set up“
Meta will set up a temporary test phone number automatically for your development. You’ll need the Phone Number ID from the WhatsApp → API Setup page later.
Generate a permanent WhatsApp access token
Production systems can’t work with standard access tokens that expire in 24 hours. Here’s what to do instead:
- Open Meta’s Business Manager and select your business
- Go to Users → System Users and create a new system user
- Set its role as Admin and click “Create System User”
- Use “Add Assets” to link this user with your WhatsApp app
- Generate a token and select “Permanent” as expiration
- Choose both
whatsapp_business_messaging
andwhatsapp_business_management
permissions - Store this token safely for later use
Create an Amazon Pinpoint project and custom endpoint
Your AWS messaging setup needs these steps:
- Access the Amazon Pinpoint console
- Create a new project with a unique name
- Enable the SMS channel in project settings
- Set up a CUSTOM endpoint in Pinpoint using a WhatsApp-registered phone number
Store WhatsApp credentials in AWS Secrets Manager
Your WhatsApp access credentials need proper protection:
- Access AWS Secrets Manager console
- Select “Store a new secret” and choose “Other type of secret”
- Enter your token as “Bearer “
- Name the secret “WhatsAppAccessToken“
- Save the secret’s ARN for later use
This setup creates a secure foundation for a reliable WhatsApp-AWS integration.
Want an Easier Way to Use the WhatsApp API?
Integrating the WhatsApp API through AWS can be complex and time-consuming. CampaignHQ makes WhatsApp automation simple—no AWS account, backend setup, or approvals required.
Try CampaignHQ’s WhatsApp ToolDesign the Messaging Architecture with AWS Services
A robust WhatsApp messaging architecture needs multiple AWS services to create reliable two-way communication channels. Your WhatsApp API prerequisites will help us design a system that handles both outbound and inbound messages well.
Amazon Pinpoint arranges outbound messages
Amazon Pinpoint provides a powerful multichannel platform that extends naturally to WhatsApp through its custom channel features. The process to send WhatsApp messages follows this efficient flow:
- Amazon Pinpoint campaign or experience targeting CUSTOM endpoint types triggers a Lambda function
- The function payload has endpoint data and the WhatsApp message template name
- Lambda gets the WhatsApp access token from Secrets Manager
- The function sends a POST request to WhatsApp’s API with the token, recipient’s number, and template
- WhatsApp delivers the message to the customer’s device
This approach helps you arrange WhatsApp communications among other channels like SMS and email. You can create unified customer experiences instead of disconnected messaging.
API Gateway and Lambda process inbound messages
WhatsApp needs a verification-ready Callback URL to handle incoming customer messages:
- Set up Amazon API Gateway as your WhatsApp webhook endpoint
- Create a Lambda function to process incoming webhook requests
- Lambda checks if the token matches the stored value when WhatsApp sends the original GET request
- Customer messages arrive as POST requests after verification
- The Lambda function gets vital data like phone number, timestamp, message ID, and content
- Lambda marks each processed message as “read” through WhatsApp’s API
This two-way setup lets you send messages and respond to customer interactions live.
Secrets Manager and environment variables protect message flow
Secure WhatsApp credentials are vital to build reliable integrations:
- Keep your WhatsApp access token in AWS Secrets Manager (format: “Bearer EEAEAE…”)
- Save verification tokens in Lambda environment variables
- Get credentials in Lambda functions only when needed
- Never hardcode sensitive values in your application code
CloudWatch metrics help you track WhatsApp activity through WhatsAppMessageFeeCount and WhatsAppConversationFeeCount. These metrics show your usage and costs over time.
Deploy the Integration Using AWS CloudFormation
The deployment process becomes simple once you have your prerequisites and architecture design ready. AWS CloudFormation helps you create all resources in one go.
Download and configure the CloudFormation template
CloudFormation templates let you deploy WhatsApp API integration through code-based infrastructure. Here’s how to start:
- Download the AWS CloudFormation template built for WhatsApp-Pinpoint integration
- Go to the AWS CloudFormation console in your preferred region
- Select “Create stack” and choose “With new resources“
- Under template selection, choose “Template is ready” and “Upload a template file”
- Upload your downloaded template file
This standard approach will give a consistent way to create all resources and makes future changes easier.
Set up API Gateway, Lambda, and Pinpoint parameters
After uploading the template, you need to set these key parameters:
- ApiGatewayName: Name for your API Gateway resource
- PhoneNumberId: Your WhatsApp phone number ID from Meta Developers console
- PinpointProjectId: Amazon Pinpoint project ID created earlier
- VerifyToken: An alphanumeric token (e.g., “123abc”) for webhook verification
- WhatsAppAccessToken: Your permanent access token starting with “Bearer EEAEAE…”
CloudFormation automatically creates and connects all resources based on your architecture design after you submit these parameters.
Configure webhook callback URL in Meta Developer Console
After your stack creation succeeds:
- Copy the API Gateway endpoint URL from CloudFormation’s outputs tab
- Go to Meta Developers App dashboard and select “Webhooks”
- Under WhatsApp Business Account settings, click “Configure Webhooks”
- Enter your API Gateway endpoint as the Callback URL
- Input the same VerifyToken value used in CloudFormation
- Select “messages” under subscription fields
- Click “Verify and Save”
Your Lambda function must respond correctly to WhatsApp’s original verification request for the verification to work. Meta’s platform starts sending live notifications about incoming messages to your AWS environment after verification.
Test and Extend Your WhatsApp Messaging System
The time has come to test your WhatsApp-AWS integration framework’s functionality and discover its advanced features. This testing phase ensures everything works smoothly before customer deployment.
Send a WhatsApp message using a Pinpoint campaign
Here’s how to test outbound messaging:
- Go to Amazon Pinpoint Campaigns and create a new “Standard campaign”
- Name it “WhatsAppCampaign” and select “Custom” as your channel
- Choose a segment containing your CUSTOM endpoint
- Select the Lambda function named “WhatsAppSendMessageLambda”
- Under Custom data type, enter “hello_world” (your WhatsApp template)
- Review settings and click “Launch campaign”
Receive and log inbound messages in CloudWatch
Testing two-way communication is simple. Just send a message from your mobile to your WhatsApp Business number. The webhook processes these incoming messages automatically and stores details in CloudWatch. You can verify message receipt and processing by checking the “WhatsAppWebHookLambda” function’s logs.
Use dynamic variables in message templates
Your templates work better with personalization. Start by creating templates with variables like {{1}} and {{2}} in the Meta Developer Console. Then update your Lambda function to replace these placeholders with dynamic content:
"You made a purchase for {{1}} using a credit card ending in {{2}}."
These variables get their values from Pinpoint endpoint attributes during transmission.
Send custom text messages within 24-hour window
A 24-hour customer service window opens each time customers message your business. You can send freestyle text messages without templates during this period. Remember that approved templates are required for messages outside this window.
Add SMS fallback for non-WhatsApp users
Some customers don’t use WhatsApp. The solution is to implement SMS fallback that reaches everyone:
- Configure Pinpoint for both WhatsApp and SMS channels
- Monitor WhatsApp delivery status
- Trigger SMS fallback when WhatsApp fails
Conclusion
AWS WhatsApp API gives developers a chance to connect with the platform’s massive 2.3 billion active user base. This piece walked you through the key steps to build a resilient WhatsApp messaging system with AWS services. We started by showing the connection between WhatsApp and AWS. Next came the prerequisites needed to work with WhatsApp Business API. The design phase helped create an adaptable messaging setup using Amazon Pinpoint, API Gateway, Lambda, and Secrets Manager.
CloudFormation templates made the infrastructure deployment quick and simple. The system testing phase involved sending outbound messages and getting inbound communications through the new channels. Real-life results prove the value – Duolingo achieved 12% better verification rates and reduced costs by 87%.
WhatsApp integration brings great value, but you might want to add more messaging options by learning about AWS SES Connect for detailed email delivery options. This creates a unified way to communicate across different channels.
FAQ
How to integrate API to WhatsApp?
The API integration with WhatsApp happens through Meta’s developer platform. You’ll need to create a Meta Developer account and set up a business application first. Here’s how the process works:
- Set up a WhatsApp Business Account (WABA) through a WhatsApp Business Solution Provider or directly via AWS End User Messaging Social
- Get your business identity verified (this process can take up to 2 weeks)
- Set up a webhook callback URL to get up-to-the-minute message notifications
- Create a permanent access token with the right permissions
Once your account is ready, you’ll need a working webhook that responds to Meta’s verification challenges correctly. AWS API Gateway works perfectly for this need. Meta’s platform sends a verification code called “HubChallenge” and your webhook must send it back exactly to create the connection.
Can AWS send a WhatsApp message?
Yes, AWS can send WhatsApp messages in several ways. We used AWS End User Messaging Social as our main service to handle WhatsApp integration. This service lets you create new WhatsApp Business Accounts or connect your existing ones right from the AWS management console.
Amazon Pinpoint is another great way to send WhatsApp messages through its custom channel feature. Here’s how it works:
- Create a Pinpoint campaign that targets CUSTOM endpoints
- Use Lambda functions to get WhatsApp credentials from AWS Secrets Manager
- Make API calls to WhatsApp with your access token and message template