AWS Messaging & Targeting Blog
Deploy Amazon QuickSight dashboard for Amazon Pinpoint engagement events.
Abstract
Business intelligence (BI) dashboards provide a graphical representation of metrics and key performance indicators (KPIs) to monitor the health of your business. By leveraging BI dashboards to analyze the performance of your customer communications, you gain valuable insights into how they are engaging with your messages and can make data-driven decisions to improve your marketing and communication strategies.
In this blog post we introduce a solution that automates the deployment of an Amazon QuickSight dashboard that enables marketers to analyze their long-term Amazon Pinpoint customer engagement data. These dashboards can be customized further depending the use case. This solution alleviates the need to create data pipelines for storage and analysis of Amazon Pinpoint’s engagement data, while offering a greater variety of widgets and views across email, SMS, campaigns, journeys and transactional messages when comparing to Amazon Pinpoint’s native dashboards.
Amazon Pinpoint is a flexible, scalable marketing communications service that connects you with customers over email, SMS, push notifications, or voice. The service offers ready to use dashboards to view key performance indicators (KPIs) for the various messaging channels, It provides 90 days of events for analysis. However, the raw events used to populate Amazon Pinpoint’s dashboards, can be streamed using Amazon Kinesis Data Firehose to a destination of your choice. This blog will walk you through leveraging this feature to create a data lake to store and analyze data beyond the initial 90 days.
Amazon QuickSight is a cloud-scale business intelligence (BI) service that you can use to deliver easy-to-understand insights in an interactive visual environment.
The solutions leverages the Amazon Cloud Development Kit (CDK) to deploy the needed infrastructure and dashboards.
Use Case(s)
The Amazon QuickSight dashboards deployed through this solution are designed to serve several use cases. Here are just a few examples:
- View email and SMS costs per Campaign and Journey.
- Deep dive into engagement insights and performance. (eg: SMS events, Email events, Campaign events, Journey events).
- Schedule reports to various business stakeholders.
- Track individual email & SMS statuses to specific endpoints.
- Analyze open and click rates based on the message send time.
These are some of the use cases you can use these dashboards for and with all the data points being available in Amazon QuickSight, you can create your own views and widgets based on your specific requirements.
Solution Overview
This solution builds upon the Digital User Engagement (DUE) Event Database AWS Solution. It creates a long-term Amazon Pinpoint event data lake. This solution also builds a QuickSight dashboard to visualize and analyze this data. It leverages several other AWS services to tie i all together. It uses AWS Lambda for processing AWS CloudTrail data, Amazon Athena to build views using SQL for Amazon QuickSight, AWS CloudTrail to record any new campaign, journey and segment updates and Amazon DynamoDB to store the campaign, journey and segment metadata. This solution can be segmented into three logical portions: 1) Pinpoint campaign/journey/segment lookup tables. 2) Amazon Athena Views. 3) Amazon QuickSight resources.
The AWS Cloud Development Kit (CDK) is used to deploy this solution to your account. AWS CDK is an open-source software development framework for defining cloud infrastructure as code with modern programming languages and deploying it through AWS CloudFormation.
Pinpoint campaign/journey/segment lookup tables
- A CloudFormation AWS Lambda-backed custom resource function adds current Pinpoint campaign, journey and segment meta data to Amazon DynamoDB lookup tables. An AWS CloudFormation custom resource is managed by a Lambda function that runs only upon the deployment, update and deletion of the AWS CloudFormation stack.
- AWS CloudTrail logs record API actions to an S3 bucket every 5 minutes.
- When an AWS CloudTrail log is written to the S3 bucket an AWS Lambda function is invoked and checks for Amazon Pinpoint campaigns/journeys/segments management events such as create, update and delete.
- For every Amazon Pinpoint action the AWS Lambda function finds, it queries Amazon Pinpoint to get the respective resource details.
- The AWS Lambda function will create or update records in the Amazon DynamoDB table to reflect the changes.
- This solution also deploys an Amazon Athena DynamoDB connector. Amazon Athena uses this to query the Amazon DynamoDB lookup tables to enrich the data in the Amazon Pinpoint event data lake.
- The Amazon Athena to Amazon DynamoDB connector requires an Amazon S3 spill bucket for any data that exceeds the AWS Lambda function limits
Amazon Athena views
Amazon Athena views are crucial for querying and organizing the data. These views allow QuickSight to interact with the Pinpoint event data lake through standard SQL queries and views. Here’s how they’re set up:
The application creates several named queries (called saved queries in the Amazon Athena console). Each named query uses a SQL statement to create a database view containing a subset of the data from the Pinpoint event data lake (or joins data from a previous view with the Amazon DynamoDB tables created above. The views are also created using an AWS Lambda-backed custom resource.
Amazon QuickSight resources
- This solution creates several Amazon QuickSight resources to support the deployed dashboard. These include data sources, datasets, refresh schedules, and an analysis. The refresh schedule determines the frequency that Amazon QuickSight queries the Amazon Athena views to update the datasets.
- Amazon Athena retrieves live data from the DUE event database data lake and the Athena DynamoDB Connector whenever the Amazon QuickSight refresh schedule runs.
Prerequisites
- Deploy the Digital User Engagement (DUE) Event Database solution before continuing
- After you have deployed this solution, gather the following data from the stack’s Resources section.
- DUES3DataLake: You will need the bucket name
- PinpointProject: You will need the project Id
- PinpointEventDatabase: This is the name of the Glue Database. You will only need this if you used something other than the default of due_eventdb
- After you have deployed this solution, gather the following data from the stack’s Resources section.
Note: If you are installing the DUE event database for the first time as part of these instructions, your dashboard will not have any data to show until new events start to come in from your Amazon Pinpoint project.
Once you have the DUE event database installed, you are ready to begin your deployment.
Implementation steps
Step 1 – Ensure that Amazon Athena is setup to store query results
Amazon Athena uses workgroups to separate users, teams, applications, or workloads, to set limits on amount of data each query or the entire workgroup can process, and to track costs. There is a default workgroup called “primary” However, before you can use this workgroup, it needs to be configured with an Amazon S3 bucket for storing the query results.
- If you do not have an existing S3 bucket you can use for the output, create a new Amazon S3 bucket.
- Navigate to the Amazon Athena console and from the menu select workgroups > primary > Edit > Query result configuration
- Select the Amazon S3 bucket and any specific directory for the Athena query result location
Note: If you choose to use a workgroup other that the default “primary” workgroup. Please take note of the workgroup name to be used later.
Step 2 – Enable Amazon QuickSight
Amazon QuickSight offers two types of data sets: Direct Query data sets, which provides real-time access to data sources, and SPICE (Super-fast, Parallel, In-memory Calculation Engine) data sets, which are pre-aggregated and cached for faster performance and scalability that can be refreshed on a schedule.
This solution uses SPICE datasets set to incrementally refresh on a cycle of your choice (Daily or Hourly). If you have already setup Amazon QuickSight, please navigate to Amazon QuickSight in the AWS Console and skip to step 3.
- Navigate to Amazon QuickSight on the AWS console
- Setup Amazon QuickSight account by clicking the “Sign up for QuickSight” button.
- You will need to setup an Enterprise account for this solution.
- To complete the process for the Amazon QuickSight account setup follow the instructions at this link
- Ensure you have the Admin Role
- Choose the profile icon in the top right corner, select Manage QuickSight and click on Manage Users
- Subscription details should display on the screen.
- Ensure you have enough SPICE capacity for the datasets
- Choose the profile icon, and then select Manage QuickSight
- Click on SPICE Capacity
- Make sure you enough SPICE for all three datasets
- if you are still in the free tier, you should have enough for initial testing.
- You will need about 2GB of capacity for every 1,000,000 Pinpoint events that will be ingested in to SPICE
- Note: If you do not have enough SPICE capacity, deployment will fail
- Please note the Amazon QuickSight username. You can find this by clicking profile icon. Example username: Admin/user-name
Step 3 – Collect the Amazon QuickSight Service Role name in IAM
For Amazon Athena, Amazon S3, and Athena Query Federation connections, Amazon QuickSight uses the following IAM “consumer” role by default: aws-quicksight-s3-consumers-role-v0
If the “consumer” role is not present, then QuickSight uses the following “service” role instead : aws-quicksight-service-role-v0.
The version number at the end of the role could be different in your account. Please validate your role name with the following steps.
- Navigate to the Identity and Access Management (IAM) console
- Go to Roles and search QuickSight
- If the consumer role exists, please note its full name
- If you only find the service role, please note its full name
Note: For more details on these service roles, please see the QuickSight User Guide
Step 4 – Prepare the CDK Application
Deploying this solution requires no previous experience with the AWS CDK toolkit. If you would like to familiarize yourself with CDK, the AWS CDK Workshop is a great place to start.
- Setup your integrated development environment (IDE)
- Option 1 (recommended for first time CDK users): Use AWS Cloud9 – a cloud-based IDE that lets you write, run, and debug your code with just a browser
- Navigate to Cloud9 in the AWS console and click the Create Environment button
- Provide a descriptive name to your environment (e.g. PinpointAnalysis)
- Leave the rest of the values as their default values and click Create
- Open the Cloud9 IDE
- Node, TypeScript, and CDK should be come pre-installed. Test this by running the following commands in your terminal.
node --version
tsc --version
cdk --version
- If dependencies are not installed, follow the Step 1 instructions from this article
- Using AWS Cloud 9 will incur a nominal charge if you are no longer Free Tier eligible. However, using AWS Cloud9 will simply setup if you do not already have a local environment with AWS CDK and the AWS CLI installed
- Node, TypeScript, and CDK should be come pre-installed. Test this by running the following commands in your terminal.
- Option 2: local IDE such as VS Code
- Setup CDK locally using this documentation
- Install Node, TypeScript and the AWS CLI
- Once the CLI is installed, configure your AWS credentials
aws configure
- Once the CLI is installed, configure your AWS credentials
- Option 1 (recommended for first time CDK users): Use AWS Cloud9 – a cloud-based IDE that lets you write, run, and debug your code with just a browser
- Clone the Pinpoint Dashboard Solution from your terminal by running the command below:
git clone https://github.com/aws-samples/digital-user-engagement-events-dashboards.git
- Install the required npm packages from package.json by running the commands below:
cd digital-user-engagement-events-dashboards
npm install
Open the file at digital-user-engagement-events-dashboards/bin/pinpoint-bi-analysis.ts
for editing in your IDE.
Edit the following code block your your solution with the information you have gathered in the previous steps. Please reference Table 1 for a description of each editable field.
const resourcePrefix = "pinpoint_analytics_";
...
new MainApp(app, "PinpointAnalytics", {
env: {
region: "us-east-1",
}
//Attributes to change
dueDbBucketName: "{bucket-name}",
pinpointProjectId: "{pinpoint-project-id}",
qsUserName: "{quicksight-username}",
//Default settings
athenaWorkGroupName: "primary",
dataLakeDbName: "due_eventdb",
dateRangeNumberOfMonths: 6,
qsUserRegion: "us-east-1",
qsDefaultServiceRole: "aws-quicksight-service-role-v0",
spiceRefreshInterval: "HOURLY",
//Constants
athena_util: athena_util,
qs_util: qs_util,
});
Attribute | Definition | Example |
resourcePrefix | The prefix for all created Athena and QuickSight resources | pinpoint_analytics_ |
region | Where new resources will be deployed. This must be the same region that the DUE event database solution was deployed | us-east-1 |
dueDbBucketName | The name of the DUE event database S3 Bucket | due-database-xxxxxxxxxxus-east-1 |
qsUserName | The name of your QuickSight User | Admin/my-user |
athenaWorkGroupName | The Athena workgroup that was previously configured | primary |
dataLakeDbName | The Glue database created during the DUE event database solution. By default the database name is “due_eventdb” | due_eventdb |
dateRangeNumberOfMonths | The number of months of data the Athena views will contain. QuickSight SPICE datasets will contain this many months of data initially and on full refresh. The QuickSight dataset will add new data incrementally without deleting historical data. | 6 |
qsUserRegion | The region where your quicksight user exists. By default, new users will be created in us-east-1. You can check your user location with the AWS CLI: aws quicksight list-users --aws-account-id {accout-id} --namespace default and look for the region in the arn |
us-east-1 |
qsDefaultServiceRole | The service role collected during Step 3. | aws-quicksight-service-role-v0 |
spiceRefreshInterval | Options Include HOURLY, DAILY – This is how often the SPICE 7-day incremental window will be refreshed | DAILY |
Step 5 – Deploy
- CDK requires you to bootstrap in each region of an account. This creates a S3 bucket for deployment. You only need to bootstrap once per account/region
cdk bootstrap
- Deploy the application
cdk deploy
Step 6 – Explore
Once your solution deploys, look for the Outputs provided by the CDK CLI. You will find a link to your new Amazon Quicksight Analysis, or Dashboard, as well as a few other key resources. Also, explore the resources sections of the deployed stacks in AWS CloudFormation for a complete list of deployed resources. In the AWS CloudFormation, you should have two stacks. The main stack will be called PinpointAnalytics and a nested stack.
Pricing
The total cost to run this solution will depend on several factors. To help explore what the costs might look like for you, please look at the following examples.
All costs outlined below will assume the following:
- 1 Amazon QuickSight author
- 100 Amazon QuickSight analysis reader sessions
- 100k write API actions for all services in AWS account
- A total of 1k Amazon Pinpoint campaigns, journeys, and segments resulting in 1k Amazon DynamoDB records
- 5 million monthly Amazon Pinpoint events – email send, email delivered, etc.
Base Costs:
- 1 Amazon QuickSight author – can edit all Amazon QuickSight resources
- $24 – There is a a 30 day trial for 4 authors in the free tier
- 100 Amazon QuickSight analysis reader sessions OR 6 readers with unlimited access – max $5 per month per reader
- $30
- Total Monthly Costs: $54 / month
Variable Costs:
Even with the assumptions listed above, the costs will vary depending on the chosen data retention window as well as the the refresh schedule.
- SPICE data storage costs.
- Total size of storage will depend on how many months you choose to display in the dashboard
- For the above assumptions, the SPICE datasets will cost roughly $3.25 for each month stored in the datasets.
- Amazon Athena data volume costs
- With Athena you are charged for the total number of bytes scanned in a query. The solution implements incremental data resfreshes in SPICE. Amazon QuickSight will only query and updates the most recent 7 days of data during each refresh cycle. This can be adjusted as needed.
Scenario 1 – 6-month data analysis with daily refresh:
- Fixed costs: $57
- SPICE datasets: $19.50
- Athena Scans: $1.25
- Total Costs: $77.75 / Month
Scenario 2 – 12-month data analysis with daily refresh:
- Fixed costs: $57
- SPICE datasets: $39
- Athena Scans: $1.25
- Total Costs: $97.25 / Month
Scenario 3 – 12-month data analysis with hourly refresh:
- Fixed costs: $57
- SPICE datasets: $39
- Athena Scans: $27.50
- Total Costs: $123.5 / Month
Note: Several services were not mentioned in the above scenarios (e.g., DynamoDB, Cloudtrail, Lambda, etc). The limited usage of these services resulted in a combined cost of less than a few US dollars per month. Even at a greater scale, the costs from these services will not increase in any significant way.
Clean up
- Delete the CDK stack running the following from your command line
cdk destroy
- Delete QuickSight account
- Follow this guide
- Delete Athena views
- Go to Glue > Data Catalog > Databases > Your Database Name
- This should delete all Athena views no longer needed. Views created will start with the resourcePrefix specified in the bin/athena-quicksight-cdk.ts file
- Delete S3 buckets
- DynamoDB cloud watch log bucket
- Dynamo Athena Connector Spill bucket
- Athena workgroup output bucket
- Delete DynamoDB tables
- This solution creates two DynamoDB lookup tables prefixed with the Stack name
Conclusion
In this blog, you have deployed a solution that visualizes Amazon Pinpoint’s email and SMS engagement data using Amazon QuickSight. This solution provides you with an Amazon QuickSight functional dashboard as well as a foundation to design and build new Amazon QuickSight dashboards that meet your bespoke requirements. Parts of the solution, such as the Amazon Athena views, can be ingested with other business intelligence tools that your business might already be using.
Next steps
This solution can be expanded to include Amazon Pinpoint engagement events from other channels such as push notifications, Amazon Connect outbound calls, in-app and custom events. This will require certain updates on the Amazon Athena views and consequently on the Amazon QuickSight dashboards. Furthermore, the Amazon DynamoDB tables store only campaign, journey and segment meta-data. You can extend this part of the solution to include message template meta-data, which will help to analyze performance per message template.
Considerations / Troubleshooting
- Pinpoint Standard account can be upgraded to an Enterprise account. Enterprise accounts cannot be downgraded to a Standard account.
- SPICE capacity is allocated separately for each AWS Region. Default SPICE capacity is automatically allocated to your home AWS Region. For each AWS account, SPICE capacity is shared by all the people using QuickSight in a single AWS Region. The other AWS Regions have no SPICE capacity unless you choose to purchase some.
- The QuickSight Analysis Event rates are calculated on Pinpoint message_id and endpoint_id grain – click rate will be the same if a user clicks an email link one or more than one times
- All timestamps are in UTC. To display data in another timezone edit event_timestamp_timezone calculated field in every dataset
- Data inside Amazon QuickSight will refresh depending on the schedule set during deployment. Current options include hourly and daily refreshes.
- AWS CloudTrail has 5 cloudtrail trails per AWS account.
About the Authors