Pinpoint
Persistence:
3 minute read
Introduction
Pinpoint is a customer engagement service to facilitate communication across multiple channels, including email, SMS, and push notifications. Pinpoint allows developers to create and manage customer segments based on various attributes, such as user behavior and demographics, while integrating with other AWS services to send targeted messages to customers.
LocalStack allows you to mock the Pinpoint APIs in your local environment. The supported APIs are available on our API coverage page, which provides information on the extent of Pinpoint’s integration with LocalStack.
Getting started
This guide is designed for users new to Pinpoint and assumes basic knowledge of the AWS CLI and our awslocal
wrapper script.
Start your LocalStack container using your preferred method. We will demonstrate how to create a Pinpoint application, retrieve all applications, and list tags for the resource.
Create an application
Create a Pinpoint application using the CreateApp
API.
Execute the following command:
$ awslocal pinpoint create-app \
--create-application-request Name=ExampleCorp,tags={"Stack"="Test"}
The following output would be retrieved:
{
"ApplicationResponse": {
"Arn": "arn:aws:mobiletargeting:us-east-1:000000000000:apps/4487a55ac6fb4a2699a1b90727c978e7",
"Id": "4487a55ac6fb4a2699a1b90727c978e7",
"Name": "ExampleCorp",
"CreationDate": 1706609789.906863
}
}
List applications
You can list all applications using the GetApps
API.
Execute the following command:
$ awslocal pinpoint get-apps
The following output would be retrieved:
{
"ApplicationsResponse": {
"Item": [
{
"Arn": "arn:aws:mobiletargeting:us-east-1:000000000000:apps/4487a55ac6fb4a2699a1b90727c978e7",
"Id": "4487a55ac6fb4a2699a1b90727c978e7",
"Name": "ExampleCorp",
"CreationDate": 1706609789.906863
}
]
}
}
List tags for the application
You can list all tags for the application using the GetApp
API.
Execute the following command:
$ awslocal pinpoint list-tags-for-resource \
--resource-arn arn:aws:mobiletargeting:us-east-1:000000000000:apps/4487a55ac6fb4a2699a1b90727c978e7
Replace the resource-arn
with the ARN of the application you created earlier.
The following output would be retrieved:
{
"TagsModel": {
"tags": {
"Stack": "Test"
}
}
}
OTP verification
The operations SentOTPMessage
and VerifyOTPMessage
are used for one-time password (OTP) verification.
On production AWS, SendOTPMessage
sends an SMS text message with the OTP code.
The OTP can then be verified against the reference ID using VerifyOTPMessage
LocalStack however can not send real SMS text messages. Instead it provides alternative ways to retrieve the actual OTP code as illustrated below.
Begin by making a OTP request:
$ awslocal pinpoint send-otp-message \
--application-id fff5a801e01643c18a13a763e22a8fbf \
--send-otp-message-request-parameters '{
"BrandName": "LocalStack Community",
"Channel": "SMS",
"DestinationIdentity": "+1224364860",
"ReferenceId": "liftoffcampaign",
"OriginationIdentity": "+1123581321",
"CodeLength": 6,
"AllowedAttempts": 3,
"ValidityPeriod": 2
}'
{
"MessageResponse": {
"ApplicationId": "fff5a801e01643c18a13a763e22a8fbf"
}
}
You can use the debug endpoint /_aws/pinpoint/<application_id>/<reference_id>
to retrieve the OTP message details:
$ curl http://localhost:4566/_aws/pinpoint/fff5a801e01643c18a13a763e22a8fbf/liftoffcampaign | jq .
{
"AllowedAttempts": 3,
"BrandName": "LocalStack Community",
"CodeLength": 6,
"DestinationIdentity": "+1224364860",
"OriginationIdentity": "+1123581321",
"ReferenceId": "liftoffcampaign",
"ValidityPeriod": 2,
"Attempts": 0,
"ApplicationId": "fff5a801e01643c18a13a763e22a8fbf",
"CreatedTimestamp": "2024-10-17T05:38:24.070Z",
"Code": "655745"
}
The OTP code is also printed in an INFO
level message in the LocalStack log output:
2024-10-17T11:08:24.044 INFO : OTP for application ID fff5a801e01643c18a13a763e22a8fbf reference ID liftoffcampaign: 655745
Finally, the OTP code can be verified using:
$ awslocal pinpoint verify-otp-message \
--application-id fff5a801e01643c18a13a763e22a8fbf \
--verify-otp-message-request-parameters '{
"ReferenceId": "liftoffcampaign",
"DestinationIdentity": "+1224364860",
"Otp": "655745"
}'
{
"VerificationResponse": {
"Valid": true
}
}
When validating OTP codes, LocalStack checks for the number of allowed attempts and the validity period. Unlike AWS, there is no lower limit for validity period.