AWS Contact Center

Creating dynamic, personalized experiences in Amazon Connect

Amazon Connect’s native integrations with other AWS services like AWS Lambda allow you to create dynamic, personalized experienced for your callers. In this blog post we will use AWS Lambda and Amazon DynamoDB to:

  1. Create an AWS Lambda function from the sample provided.
  2. Integrate your Lambda function with your Amazon Connect instance, letting you perform a data dip for name and membership level (Silver, Gold, or Platinum) based on the caller’s phone number.
  3. Route the call to the corresponding queue within your contact flow.


For our AWS Lambda function to execute successfully, AWS Lambda requires an AWS Identity and Access Management (IAM) role and policy with the appropriate permissions. Use the following steps in this post to create a sample role and policy for AWS Lambda functions to access all Amazon DynamoDB tables.

Creating an IAM Policy

  1. In your AWS console, open AWS Identity and Access Management here.
  2. In the navigation pane, choose Policies, Create policy.
  3. Choose the JSON tab and paste the following text into the editor:
    	"Version": "2012-10-17",
    	"Statement":  [
    			 "Effect": "Allow",
    			"Action": [
    			"Resource": "*"
  4. Name this policy lambdaDynamo and choose Create Policy.

Creating an IAM role

  1. In the navigation pane, choose Roles, Create new role.
  2. Choose Lambda as the AWS service that will use this role and choose Next.
  3. In the Filter search bar, type the name of the policy created earlier: lambdaDynamo.
  4. Choose the lambdaPolicy policy check box, choose Next:TagsNext:Review.
  5. Name your role lambdaDynamoRole and choose Create role.

Amazon Connect Instance creation

In this post, you will require full administrative access to your Amazon Connect instance. For more information about setting up your instance, see any of the following:

  1. Amazon Connect Administrator Guide
  2. Amazon Connect User Guide
  3. Getting started with Amazon Connect (video)

Amazon DynamoDB integration

Amazon DynamoDB is a fast and flexible NoSQL database service for all applications that need consistent, single-digit millisecond latency at any scale. It is a fully managed cloud database and supports both document and key-value store models. Its flexible data model, reliable performance, and automatic scaling of throughput capacity, makes it a great fit for storing and referencing caller information from Amazon Connect.

  1. In your AWS console, open Amazon DynamoDB and choose Create table here.
  2. On the Create DynamoDB Table page, set your Table name to membershipTable and set the Primary key to phoneNumber.
  3. Choose Add sort key, and label it membershipLevel.
  4. Verify that all entries on the page are accurate, and choose Create.
  5. Wait for the table creation to complete, and for your table status to change to Active.
  6. Choose membershipTable, Indexes tab, and Create index.
  7. Enter phoneNumber for the Primary key, and choose Create index.
  8. Wait for the index creation to complete, and for your table status to change to Active.
  9. Choose membershipTable, the Items tab, and Create item.
  10. In the phoneNumber field, enter the phone number that you’ll use to test your completed contact flow, make sure to include the “+” country code, enter Platinum for the membershipLevel, and choose Save.
  11. Verify that the entry is correct. A phoneNumber mismatch causes the membershipLevel lookup to fail. As a result, you can’t determine the membershipLevel of the caller.

You can repeat steps 9 through 11 for as many phone numbers as you need.

For more information about Amazon DynamoDB, see the DynamoDB documentation here.

AWS Lambda integration

AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time that you consume. There is no charge when your code is not running. Upload your code and Lambda takes care of everything required to run and scale your code with high availability. With AWS Lambda and Amazon Connect, you can pass and return custom key-value pairs allowing for multiple integration points within your contact flows.

  1. In your AWS console, open AWS Lambda and choose Create Lambda function here.
  2. Choose Author from scratch.
  3. Name your function getMembership, choose Node.js 8.10 as the Runtime, and choose Create function.
  4. For your Lambda configuration, choose lambdaDynamoRole for Execution role, increase Timeout to 8 seconds, verify the settings, and choose Save.
  5. Replace the text in Lambda function code with the following sample code and choose Save:
    var AWS = require("aws-sdk");
    var docClient = new AWS.DynamoDB.DocumentClient();
    exports.handler = (event, context, callback) => {
    	var phoneNumber = event.Details.ContactData.CustomerEndpoint.Address;
    	var paramsQuery = {
    				TableName: 'membershipTable',
      				KeyConditionExpression: "phoneNumber = :varNumber",
      				IndexName: "phoneNumber-index",
      				ExpressionAttributeValues: {
       					":varNumber": phoneNumber
    	docClient.query(paramsQuery, function(err, data) {
      		if (err) {
       			console.log(err); // an error occurred
    		else {
       			console.log("DynamoDB Query Results:" + JSON.stringify(data));
       			if (data.Items.length === 1) {
    				var membershipLevel = data.Items[0].membershipLevel;
    				callback(null, buildResponse(true, membershipLevel));
    			else {
        			console.log("PhoneNumber not found");
        			callback(null, buildResponse(true, "none"));
    function buildResponse(isSuccess, membershipLevel) {
     	if (isSuccess) {
      		return { 
    			membershipLevel: membershipLevel,
    			lambdaResult: "Success"
    	else {
      		console.log("Lambda returned error to Connect");
      		return { lambdaResult: "Error" };
  6. Choose Select a test event and Configure test events.
  7. Copy the test payload below, edit the +14805551212 value, and change it to the same phoneNumber value that you entered in your membershipLevel DynamoDB table:
      "Name": "ContactFlowExecution",
      "Details": {
        "Parameters": {
          "key1": "value1",
          "key2": "value2"
        "ContactData": {
          "ContactId": "ASDAcxcasDFSSDFs",
          "InitialContactId": "Acxsada-asdasdaxA",
          "PreviousContactId": "Acxsada-asdasdaxA",
          "Channel": "Voice",
          "InstanceARN": "",
          "InitiationMethod": "INBOUND/OUTBOUND/TRANSFER/CALLBACK",
          "SystemEndpoint": {
            "Type": "TELEPHONE_NUMBER",
            "Address": "01234567"
          "CustomerEndpoint": {
            "Type": "TELEPHONE_NUMBER",
            "Address": "+14805551212"
          "Queue": {
            "Name": "PrimaryPhoneQueue",
            "ARN": ""
          "Attributes": {
            "key1": "value",
            "key2": "value"
  8. In the Configure test event window, replace the text with the text that you edited, and choose Create.
  9. Choose Test to execute your Lambda function.
  10. Make sure that your output displays Platinum for the membershipLevel, and Success for the lambdaResult

    Troubleshooting tips: If you experience an error, it may have occurred because of insufficient IAM permissions, incorrect DynamoDB configuration, or a missing DynamoDB table index. If you fail to look up the membershipLevel for the phoneNumber and get none for the membershipLevel, your test event phoneNumber and DynamoDB table phoneNumber might be mismatched. The Log output section of your results normally indicates why the failure occurred.

Grant Amazon Connect permission to execute your Lambda function

  1. Grant your Amazon Connect instance to invoke your Lambda function by following the instructions in the Amazon Connect Administrator guide here.
  2. Verify that the permissions have been added correctly and you can see the Lambda function added to your Connect instance. If your Connect instance doesn’t have the proper permissions, your getMembership lookup will fail. As a result, you won’t be able determine the membershipLevel of the caller.

Creating your queues, routing profiles, and configuring your users

  1. In your Amazon Connect instance, choose Routing from the navigation bar, and choose Queues.
  2. Choose Add new queue, enter Silver for the Name.
  3. Choose your Hours of operation, Outbound caller ID number, Outbound caller ID name, and Add new queue.
  4. Repeat steps 2 and 3 for the Gold and Platinum queues.
  5. In your Amazon Connect instance, choose Users from the navigation bar, and choose Routing profiles.
  6. Choose Add new profile, enter Silver for the Name and Silver profile for the Description.
  7. Choose the Silver queue for Routing profile queues, Silver queue for Default outbound queue and Add new profile.
  8. Repeat steps 6 and 7 to create Gold and Platinum routing profiles.
  9. In your Amazon Connect instance, choose Users from the navigation bar, and choose User management.
  10. Choose the check boxes next to the users that you want to add to the Silver queue, and Edit.
  11. Under Routing Profile, choose the Silver routing profile, and Save.
  12. Repeat steps 10 and 11 for the Gold and Platinum users.

Creating your dynamic personalized contact flow in Amazon Connect

  1. In your Amazon Connect instance, select the Routing icon from the navigation bar, and choose Contact flows.
  2. Choose Create contact flow and drag a Play prompt block from the Interact section of the navigation bar. Connect the arrows, as shown in the following diagram:
  3. Choose the heading of the Play Prompt block to edit it, choose Text to speech (Ad hoc), enter the text Welcome to Amazon Connect, and choose Save.
  4. Drag an Invoke AWS Lambda function block from the Integrate section of the navigation bar. Connect the arrows, as shown in the following diagram:
  5. Choose the heading of the Invoke AWS Lambda block to edit it, choose your getMembership Lambda function, and Save.
  6. Drag a Check contact attributes block from the Branch section of the navigation bar. Connect the arrows, as shown in the following diagram:
  7. Choose the heading of the Check contact attributes block to edit it, choose External for Attribute to checkmembershipLevel for the value, choose Add another condition, add a Equals condition for each membershipLevel, and Save.
  8. Drag a Set queue block from the Set section of the navigation bar and choose the heading of the Set queue block to edit it.
  9. Choose the Silver queue, connect this block to the Silver value from your Check contact attributes block, and repeat this step for the Gold and Platinum queues.
  10. Drag an arrow from No match to Set queue: Silver block for a default route, as shown in the following diagram:
  11. Drag a Transfer to queue block from the Terminate/Transfer section of the navigation bar. Connect the arrows, as shown in the following diagram:
  12. Enter a name for your contact flow, choose the drop-down arrow next to Save, and choose Save & Publish.

Associate a phone number with your contact flow

  1. In your Amazon Connect instance, choose the Routing icon from the navigation bar, and choose Phone numbers.
  2. Choose the phone number to associate with your new contact flow to edit it. Choose the name of your contact flow from the Contact flow/ IVR drop-down menu, and choose Save.
  3. Log in users and call the phone number you claimed from the phoneNumber you set in your DynamoDB membershipTable to test.


Creating dynamic, personalized experiences with Amazon Connect contact flows allows you to increase the quality of experience for your callers, decrease hold times, and offer self-service opportunities or custom messages. For example, you can use the same methods outlined in this post to identify that a caller is late on their payment and offer to collect it securely using the method outlined in the blog post here.