Giter Site home page Giter Site logo

davelemons / digital-user-engagement-reference-architectures Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aws-samples/communication-developer-services-reference-architectures

0.0 0.0 0.0 1.76 MB

AWS Amazon Pinpoint and Amazon Simple Email Service (SES) Digital User Engagement Reference Architectures with CloudFormation templates.

License: MIT No Attribution

JavaScript 100.00%

digital-user-engagement-reference-architectures's Introduction

AWS Digital User Engagement Reference Architectures

A repository of reference architectures for AWS Digital User Engagement services, Amazon Pinpoint and Amazon Simple Email Service (SES), and other AWS services.

Table of Contents


Amazon SES Basics


SES Event Processing

Description

Like many other IT functions, sending emails requires operational oversight and ongoing management. One such consideration for executing any email delivery is reputation management by means of event processing. SES should be configured to emit events regarding email activity. Many events can be generated by SES, but two that are of high concern are Bounces (the recipient's mail server permanently rejected the email) and Complaints (the email was successfully delivered to the recipient, however recipient marked the email as spam). Failing to respond to these events will damage sending reputation.

The architecture below shows how SES can be configured to emit events to SNS which is then routed SQS and finally to a Lambda for processing. The Lambda function should then evaluate the events and for Bounces and Complaints, update the email address source database and remove the offending addresses from future sends.

Additionally, the Lambda function should be configured to make use of the SES Account Level Suppression List functionality to automatically suppress this email address from future sends.

Architecture Diagram

Screenshot

Use-Case

  • Best Practices configuration when sending emails
  • Maintain high sending reputation
  • Adhere to customer complaints and feedback

AWS CloudFormation Link

CF Template

Documentation References


SES Auto Reply

Description

Most of the time, the outgoing email address used to send email w/SES and Pinpoint is not setup to receive emails (aka No-Reply). It is often expected, however, that should somebody reply to such an email, that they would receive an automated guidance/confirmation that the address is not monitored and possibly who and how to reach for assistance. If that is not specifically configured, using such a non-existing email address would lead to an unhelpful and unprofessional server rejection due to address not being registered.

The architecture below allows one to deploy a templated auto-response behavior for a SES/Pinpoint domain/email address. A new rule is added to the SES Email Receiving Rule Set. The rule can be limited to specific email address, specific domain, or just be set to be across all domains. It can also have the default response address set or simply reuse the address that the original email was sent to. Once the rule is set, it is pointed to a Lambda function. Finally the latter looks up the chosen Pinpoint template and uses it to reply back. The template subject is used as the prefix for the original email subject. Optional template tag %%NAME%% is replaced with the original email's FROM and %%ID%% with the SES email message id.

Notes:

  1. While most of the configuration is done on the SES side (as that is the one processing received emails), even so called "Pinpoint-only" deployments can use this approach as the email configurations are shared between the two services already.
  2. Ensure your SES domain is verified and you are out of the sandbox. If still in the sandbox, you can only send email to the Amazon SES mailbox simulator and to email addresses/domains that you have verified.
  3. It is assumed that no additional tracking and actions are needed on such rejected and auto-replied emails, but you can further modify the flow by moving the rule around, adding more actions, and even specifying a particular SES Configuration Set.
  4. Pinpoint template instead of SES template is used as the latter does not currently have Console interface allowing for easier modification.

Architecture Diagram

Screenshot

Use-Case

  • Common practice configuration when sending emails
  • Professional auto-reply to emails sent to the configured sending email addresses

AWS CloudFormation Link

CF Template

Documentation References


Amazon Pinpoint Basics

Amazon S3 Triggered Endpoint Imports

Description

Even though Pinpoint has great API support to stream endpoint data to Pinpoint in realtime, many customers operate in a batch world and are used to loading data between systems in a batch method. Pinpoint has the ability to import data from CSV or JSON files from Amazon S3 specifically for this use-case. This could be used in a nightly batch process to update all Pinpoint Endpoints with the most recent data and preferences, or on a much smaller interval.

The architecture below will set up an infrastructure to automatically trigger when a new file is placed in an S3 bucket. The process, managed by an AWS Step Functions state machine, will start a Pinpoint import process, wait for it to complete, and send notifications that the job started, successfully finished, or failed.

For notifications, the below architecture uses SNS which allows for notifications to be sent to humans (ex: Email, SMS) or other systems that can read from the SNS topic. The notifications include the details of the import job so that quick action can be taken and records of past import jobs can be retained. The SNS Topic to subscribe to for notifications is found as an output parameter of the CloudFormation template.

With this architecture, development teams can simply save JSON or CSV formatted files for import in the designated S3 location and the process will manage the rest. It will provide detail logging in CloudWatch and send SNS notifications.

Architecture Diagram

Screenshot

Use-Case

  • Nightly Batch Endpoint Updates
  • Ad-hoc Batch Endpoint Updates
  • Triggered Imports with Status Alerts
  • Operational notifications of import jobs

AWS CloudFormation Link

CF Template

Documentation References


Automatic Phone Number Validate

Description

Pinpoint includes a phone number validation service that you can use to determine if a phone number is valid, and to obtain additional information about the phone number itself. For example, when you use the phone number validation service, it returns the following information:

  • The phone number in E.164 format.
  • The phone number type (such as mobile, landline, or VoIP).
  • The city and country where the phone number is based.
  • The service provider that's associated with the phone number.

The API is useful for verifying phone numbers provided on a web form, cleaning your existing contact database, or to help determine if SMS is supported for a given phone number allowing you to fallback to Voice if necessary.

The architecture below will setup a Pinpoint segment of all unverified phone numbers by looking for a new endpoint attribute: PNV_PhoneNumberValidated. When the included State Machine is executed, it will export all the unverified numbers using that segment, perform verification on every number, and write back to Pinpoint as endpoint attributes the result of the API call including endpoints like: PNV_Carrier, PNV_City, PNV_Country, PNV_PhoneType, PNV_Timezone, PNV_ZipCode, and PNV_PhoneNumberValidated.

This architecture could be triggered from the Amazon S3 Triggered Endpoint Imports architecture above to perform validation on all newly imported endpoints automatically upon import. This could be done by setting up a Lambda function to listen to the SNS topic published from the import architecture that calls the execute method of the state machine.

Architecture Diagram

Screenshot

Use-Case

  • Verifying phone numbers provided on a web form
  • Cleaning your existing contact database
  • Determine best channel (SMS or Voice) for a number
  • Operational notifications of Phone numbers validated

AWS CloudFormation Link

CF Template

Documentation References


Automatic Amazon Pinpoint Campaign Creation

Description

Pinpoint's UI allows marketers and non-technical users an easy way to create campaigns. There are times when creating campaigns needs to be done programmatically via the API. Further, this scheduled of campaigns could be event-triggered and also provide operational metrics via SNS notifications to when campaigns are scheduled and include success or failure alerting.

The architecture below will setup a simple State Machine that will execute a campaign immediately using the input state machine input:

{
  "SegmentId": "...",
  "SegmentName": "...",
  "SmsTemplateName": "...",
}

It will immediately start the campaign and then wait for it to finish providing operational insights in an SNS topic including: Campaign Status, Actual Start Time, Actual Finsih Time, and Successful and Total Endpoint Count.

This architecture could be triggered from the Amazon S3 Triggered Endpoint Imports architecture above to send messages immediately upon an import. It could be chained with the Amazon S3 Triggered Endpoint Imports and Automatic Phone Number Validate to send SMS messages after numbers have been imported and then immediately verified for sending. This can be done by deploying Lambda functions to each SNS topic that initiates the next state machine. See Triggered Imports, Phone Validate, Campaign Create below.

Architecture Diagram

Screenshot

Use-Case

  • Automatically fire off messages upon file imports
  • Set up welcome messages to be sent when new files are exported
  • Set up timers to create campaigns on your own schedule
  • Operational notifications of campaign statuses

AWS CloudFormation Link

CF Template

Documentation References


Pinpoint Event Processing

Description

Like many other IT functions, sending emails requires operational oversight and ongoing management. One such consideration for executing any email delivery is reputation management by means of event processing. Pinpoint should be configured to emit events regarding email sends. Many events can be generated by Pinpoint, but two that are of high concern are Bounces (the recipient's mail server permanently rejected the email) and Complaints (the email was successfully delivered to the recipient, however recipient marked the email as spam). Failing to respond to these events will damage sending reputation.

Since Pinpoint uses Amazon Simple Email Service to send all emails, we can rely on the above SES Event Processing Architecture to manage bounces and complaints for both SES and Pinpoint.

Architecture Diagram

Screenshot

Use-Case

  • Best Practices configuration when sending emails
  • Maintain high sending reputation
  • Adhere to customer complaints and feedback

AWS CloudFormation Link

CF Template

Documentation References


Pinpoint S3 Event Database

Description

Sending outbound messages with Pinpoint allows you to track engagement events both in the Pinpoint console and programmatically by consuming the raw events that Pinpoint (and SES) generate. These events provide a wealth of knowledge on how your end-users are engaging with your messaging and Pinpoint allows you to stream these events to S3 to create a data lake which is excellent for mining, analysis, and future machine learning training and retraining.

The architecture below shows how Pinpoint can be configured to emit events through Kinesis Firehose into Amazon S3. SES will also be configured to use Pinpoint as an Event Destination, using the SESv2 API, to route all SES email events into the same S3 destination. Finally, it will register the event schema with Athena and Glue to create a single table for all events, and a series of Views, one for each event type.

This enables Athena Queries to be run against each event type as a flattened view, allowing for queries like:

Ex: Get all Campaigns with Opens, Clicks, Hard Bounces, Soft Bounces, and Unsubscribes

SELECT
  pinpoint_campaign_id,
  (SELECT COUNT(*) FROM email_send WHERE email_send.pinpoint_campaign_id = campaign_send.pinpoint_campaign_id) AS NumSends,
  (SELECT COUNT(*) FROM email_open WHERE email_open.pinpoint_campaign_id = campaign_send.pinpoint_campaign_id) AS NumOpens,
  (SELECT COUNT(*) FROM email_click WHERE email_click.pinpoint_campaign_id = campaign_send.pinpoint_campaign_id) AS NumClicks,
  (SELECT COUNT(*) FROM email_hardbounce WHERE email_hardbounce.pinpoint_campaign_id = campaign_send.pinpoint_campaign_id) AS NumHardBounces,
  (SELECT COUNT(*) FROM email_softbounce WHERE email_softbounce.pinpoint_campaign_id = campaign_send.pinpoint_campaign_id) AS NumSoftBounces,
  (SELECT COUNT(*) FROM email_unsubscribe WHERE email_unsubscribe.pinpoint_campaign_id = campaign_send.pinpoint_campaign_id) AS NumUnsubs

FROM campaign_send
WHERE ingest_timestamp > current_timestamp - interval '30' day
GROUP BY pinpoint_campaign_id


Ex: Find all emails received by an email address in the last 30 days and check to see if it was opened

SELECT
  a.event_timestamp as WhenSent,
  a.subject as EmailSubject,
  CASE WHEN b.event_timestamp IS NULL THEN 0 ELSE 1 END as DidOpen
FROM email_send a
LEFT JOIN email_open b
  ON a.message_id = b.message_id
WHERE contains(a.destination, '[email protected]')
  AND a.ingest_timestamp > current_timestamp - interval '30' day
ORDER BY a.event_timestamp DESC

Architecture Diagram

Screenshot

Use-Case

  • Data Mining
  • Engagement Scoring
  • Engagement Analysis
  • Campaign Reporting
  • Click and Open Tracking
  • Machine Learning Training / Retraining

AWS CloudFormation Link

CF Template

Documentation References


Pinpoint Message Archiver

Description

Many organizations need to keep records of messages sent to end-users. Using the Pinpoint Event Stream, we are able to archive all Campaign and Journey messages reliably in Amazon S3 by re-rendering the message using the content provided.

The Architecture below shows how an Archiving solution could be built by attaching an AWS Lambda function to an existing Kinesis Firehose used as a Pinpoint Event Stream. We configure the Lambda function to look for the _campaign.send and _journey.send events processing the archival asynchronously using Amazon Simple Queue Service.

The result are MIME-typed files stored in Amazon S3 with the Key Prefix: /archive/[EndpointId]/[Year]/[Month]/[Day]/[Hour]. This allows for easy GDPR compliance by enabling deletion of all messages belonging to the same Endpoint ID very quickly.

Architecture Diagram

Screenshot

Use-Case

  • Compliance requiring historical record of all messages sent to an Endpoint
  • Better customer service being able to lookup each messages sent to a user

AWS CloudFormation Link

CF Template

Lambda Source

Documentation References


Add / Remove from Segments via Event Activity

Description

Amazon Pinpoint can act as an event hub for events generated by engaging with end users (Email Opens, Email Clicks, Email Complaints, SMS Sends, etc). Pinpoint can also be used to stream custom events from applications via the PutEvents API. This is how AWS Amplify sends events to Pinpoint about mobile and web applications. All of these events can be streamed out of Pinpoint via the Pinpoint Event Stream allowing all of these events to be routed to the same destination for processing or storage. A common pattern is to use these events to target endpoints into Pinpoint Segments. Pinpoint's Dynamic Segment functionality allows for users to generate segments for Campaign or Journey targeting based on custom endpoint attributes.

The architecture below shows how an AWS Lambda function can be used to read the events coming from the Pinpoint event stream via Kinesis in order to find specific events that will trigger Endpoint attributes to be updated in near real time. The deployed Lambda function looks for email open events and custom webinar registration events.

Using this example, a marketer could create a Dynamic Segment in Pinpoint of users who have opened an email (attribute "email_opened" = "true") and who have registered for Webinar 5 (attribute "webinar_registration" = "webinar5"). This segment will be continuously updated so that Campaigns and Journeys would always have the most recent data.

Architecture Diagram

Screenshot

Use-Case

  • Using Event Data to create dynamic segments
  • Target Users with Campaigns based on custom events
  • Target Users with Journeys based on custom events

AWS CloudFormation Link

CF Template

Documentation References


Amazon Pinpoint SMS


Self-Managed Opt Outs

Description

Managing communication preferences for the SMS channel are very important. The STOP keyword is an important keyword to monitor when sending out SMS messages to end-users. By default, AWS will manage the STOP keyword (and other related keywords) on your behalf. If customers respond with STOP, then AWS will put that phone number on an opt out list per AWS account thereby blocking further communication with that end-user. This will keep you in compliance will sending SMS messages, but it is not ideal for transactional messaging such as One-Time Passwords, Confirmation Messages, or Receipts.

Amazon Pinpoint allows you to configure Self-Managed Opt Outs which will allow you to bypass AWS's built in controls. The architecture outlined below takes deploys an SNS Topic and Lambda function that will listen to and respond to the STOP keyword in two-way SMS conversations.

Architecture Diagram

Screenshot

Use-Case

  • Adhere to STOP keyword compliance rules
  • Still allow for sending Transactional messaging after STOP keyword
  • Used in One-Time Password, Confirmation, and Receipt messaging
  • Allow other customer systems to be notified of STOP triggers

AWS CloudFormation Link

CF Template

NOTE: Amazon Pinpoint does not allow you to configure two-way SMS or self-managed opt outs via API. This can only be done via the Console. After deploying the CloudFormation template, go into Pinpoint and turn on both Two-Way SMS, selecting the newly deployed SNS Topic, and also Self-Managed Opt Out per the documentation linked below.

Documentation References


Sending SMS Triggered by S3 File Drop

Description

Amazon Pinpoint's SendMessages API can be used to send both Transactional and Promotional SMS messages. This repository shows how to use a CSV file drop in Amazon S3 to trigger a send via Amazon Pinpoint.

Many times, third party tools can be used to generate a targeted list of users for an SMS campaign. By dropping a file into S3, we can trigger the SMS messages to go out within milliseconds.

This solution takes advantages of an Amazon SQS FIFO Queue to ensure that we are able to control the concurrency of AWS Lambda functions being invoked as to not cause throttling exceptions. If using SMS Long Codes, it might be smart to include a Sleep(xxx) as long codes are limited to 1 per second. Short codes have a default rate limit of 100 per second.

This solution is written in Python and uses a CloudFormation Template.

This solution expects a CSV file as per the example file. If making changes, please review both Lambda functions.

Prereqs:

  • Name of a unique Amazon S3 Bucket to create
  • Amazon Pinpoint Project setup
  • A short or long code provisioned in Amazon Pinpoint

Architecture Diagram

Screenshot

AWS CloudFormation Link

CF Template

Documentation References


Amazon Pinpoint Extensibility


Advanced Segmentation with Amazon S3 and Amazon Athena

Description

Endpoints stored in Amazon Pinpoint enable customers to store addresses across multiple channels all connected to each other via a UserId to represent a single user. Endpoints also enable you to store User and Endpoint level attributes to be used in Message personalization and Dynamic Segmentation. This allows for segmentation like "Where [Attribute Name] is [Some Value]". Ex: Select all Email endpoints where the User CustomerStage is Renewal and User CustomerValue is High.

Some segmentation use-cases call for more advanced segmentation rules where simple attribute matching will not be sufficient. In these cases, we can use customer's existing Data Lakes in Amazon S3 with Amazon Athena as a query engine. With these services, customers can create segments with much more specificity. Ex: Select all Email endpoints where the User has made a purchase of red shoes in the last 3 months and has opened more than 15 emails in the last 9 months and has clicked on the website page showing product details of our upcoming shoe release in the last 24 hours.

One option is to create a static import segment from these results that is updated daily. Another option, and represented in the diagram below, is to update an Endpoint attribute array AdvancedSegmentTarget with a token signaling they match the criteria. The AdvancedSegmentTarget array would then contain the names of all of the advanced segments the endpoint matches. This allows the dynamic segment to be better used in Journeys and Recurring campaigns. This process could be set up to refresh daily via Amazon CloudWatch events and orchestrated by AWS Step Function.

Architecture Diagram

Screenshot

Use-Case

  • Advanced segmentation rules
  • Utilize existing S3 Data Lakes
  • Avoid moving data into Pinpoint Attributes that changes frequently

AWS CloudFormation Link

CF Template

Documentation References


Send-Time Amazon Pinpoint Campaign Attributes

Description

In a typical Marketing Platform, in order to use a value in an email, it must exist inside the Marketing Platform. This typically involves creating Pipeline processes to select, transform, transfer, and load data from source systems into the Marketing Platform at regular intervals to sync it. This causes data latency if the data changes frequently, but can also cause long development delays when Marketers want to onboard new sources of data for use in Campaigns.

With Amazon Pinpoint's CampaignHook functionality, data can be retrieved at the time of Campaign execution from any source via a Lambda function that is called in realtime. The architecture diagram below shows how a Lambda function could be used to fetch a personalized offer from a source data store to be used in the email html without storing the offer in Pinpoint.

Architecture Diagram

Screenshot

Use-Case

  • Retrieving data in real time with no latency
  • Avoid costly and time consuming ETL processes
  • Onboard new attributes dynamically

AWS CloudFormation Link

CF Template

Documentation References


External Amazon Pinpoint Campaign Templates

Description

Amazon Pinpoint has template management functionality to managed your Email, SMS, Push, and Voice templates for your campaigns. Many customers, however, already have content in other systems driven by the needs of the Creative team. Pinpoint is flexible and extensible in that it can fetch whole HTML content from other sources at send time.

With Amazon Pinpoint's CampaignHook functionality, html and subject lines can be retrieved at the time of Campaign execution from any source via a Lambda function that is called in realtime. The architecture diagram below shows how a Lambda function could be used to fetch html from a source data store to be used in the campaign.

Architecture Diagram

Screenshot

Use-Case

  • Templates stored in a Content Management System
  • Templates managed and owned by separate creative team
  • Complex business rules where templates can be internationalized an selected at campaign send time
  • Build your own templating engine outside of Pinpoint

AWS CloudFormation Link

CF Template

NOTE: In the campaign, a message body would need to be used to minimally render the dynamic attribute "html". An example email body would be:

<!DOCTYPE html>
<html>{Attributes.html}</html>

Documentation References


Connect (or Facebook, WhatsApp, Twitter, anything) as a Pinpoint Campaign Channel

Description

Amazon Pinpoint has a voice channel that can be used to place outbound calls and play a message. Amazon Connect is a separate AWS service that has full call center capabilities. Commonly, customers will want to use Pinpoint's campaign functionality to filter and identify customers to target for an interactive outbound call.

With Amazon Pinpoint's CampaignHook functionality, Amazon Connect can be set up as a custom channel via a Lambda function. The architecture diagram below shows how a Lambda function could be used to initiate a realtime call to Connect to place an outbound call.

It is important to note that this same Lambda Pinpoint CampaignHook feature can be used to build any custom channel. Customers are not limited to other AWS services.

Architecture Diagram

Screenshot

Use-Case

  • Appointment Confirmation: You have an appointment soon. Push 1 to confirm, Press 2 to speak to someone about rescheduling
  • Automatically connect customers to agents
  • Use an advanced IVR system for interactivity with customers

AWS CloudFormation Link

CF Template

NOTE: This example uses the Pinpoint channel type of SMS. Via the UI, a message can be passed to the Lambda function by providing an SMS message during the Campaign creation process.

This also assumes that an Amazon Connect Instance, Queue, and Contact Flow have been set up and created prior to launching the CloudFormation template. These are required parameters for the template.

Documentation References


Combining Multiple References Together

Triggered Imports, Phone Validate, Campaign Create

Chaining the Amazon S3 Triggered Endpoint Imports, Automatic Phone Number Validate, and Automatic Amazon Pinpoint Campaign Creation reference architectures together can create a import pipeline to automatically import files as they land in S3, perform phone number validation on all new numbers, then kick off a campaign automatically.

AWS CloudFormation Link

CF Template


License

This library is licensed under the MIT-0 License. See the LICENSE file.

digital-user-engagement-reference-architectures's People

Contributors

amazon-auto avatar ilasoft avatar ryanjlowe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.