AWS Contact Center

Automatically Distribute Scheduled Reports for Amazon Connect

Data is critical in contact centers. Supervisors and managers rely on reports to tell them how their teams are performing and to plan for staffing requirements. Providing people with the data they need, when they need it, is vital. This blog post describes how to enable generated reports and send them automatically to users via email using:

This post also shows using AWS CloudFormation to simplify the deployment.

The solution in this post uses the native reporting capabilities in Amazon Connect to configure and schedule the report. That scheduled report is delivered to an S3 bucket that you specify in your Amazon Connect configuration. When the report is delivered to S3, it triggers an event that fires off a Lambda function. The Lambda function reads the event, retrieves the report from S3, and delivers it to the email addresses specified. All activity is logged to CloudWatch for tracking purposes.

Let’s get started.

To complete this setup, you need the following:

  1. An active AWS account.
  2. An Amazon Connect instance in either us-east-1(N. Virginia) or us-west-2(Oregon). Only these two are supported for this configuration as Amazon SES is only available in those Amazon Connect regions. After you create your instance, claim a phone number for it. For more information, see Getting Started with Amazon Connect.
  3. Amazon SES configured on your account. This solution uses Amazon SES to send the reports via email to their designated recipients. To send emails using SES, verify your From address to show that you own it. If you are in the sandbox, you also must verify your To addresses. You can verify email addresses or entire domains. For information about the verification process, see Verifying Identities in Amazon SES. For information about having your account removed from the sandbox, see Moving Out of the Amazon SES Sandbox.
  4. The appropriate IAM permissions to execute this CloudFormation template. This includes the rights to create IAM roles and Lambda functions. Additionally, you need the rights to execute CloudFormation templates, and to add an event to an S3 bucket. If you are unsure of your permissions, contact your company’s AWS administrator.

Building the Foundation

To simplify the steps involved in this configuration, I’ll use AWS CloudFormation. CloudFormation allows you to quickly deploy resources using templates. The template created for this post creates the IAM role and Lambda function.

Before you run the template, gather some information from your Amazon Connect instance. Specifically, the name of the S3 bucket where your exported reports are stored, and the bath to the reports folder. You can find this information in the Amazon Connect console, under the Data Storage section. The location should look similar to this:


Using this example, the bucket name is everything before the first forward slash, or “mybucketname.” And the reports path is everything after the first forward slash, or “connect/myinstancename/Reports”. To find these values:

  1. Open the Amazon Connect console.
  2. Choose the instance alias that you wish to use.
  3. In the left navigation, choose Data storage.
  4. In the Data Storage section, you will find the information as shown below.

To use the CloudFormation template:

  1. Open the AWS Management Console.
  2. Open the CloudFormation template. This opens the CloudFormation console .
  3. On the Select Template page, choose Next.
  4. On the Specify Details page, change the values for all parameters as described in the parameters section.
  5. Choose Next, and then on the Options page, keep all values and choose Next.
  6. On the Review page, review the warning about IAM role creation, and select the check box to acknowledge that AWS CloudFormation might create IAM resources.
  7. Choose Create.
  8. Wait for the status to update from CREATE_IN_PROGRESS to CREATE_COMPLETE. Once the deployment is complete, proceed with the next section, “Modifying the Deployment”.

Modifying the Deployment

Now that the foundation has been set, you must make a few changes for the configuration to work. Modify the IAM role that was created, add an event trigger to the S3 bucket, and configure Amazon Connect to run scheduled reports.

To modify the IAM role:

  1. Open the CloudFormation console.
  2. Choose the Stack named ConnectReportsDistributor.
  3. On the Stack Detail page, expand the Outputs section.
  4. Copy the IAM value.
  5. Open the IAM Console in a new tab in your browser.
  6. In the left navigation pane, choose Roles.
  7. In the Search box, paste the IAM value that you copied. The list of roles should filter down to the correct one.
  8. Click the Role name.
  9. Expand the ConnectReportsDistributor inline policy.
  10. Choose Edit policy.
  11. Choose the JSON tab.
  12. On line 22, replace replacewithyourbucket with the name of your bucket. It should look similar to the following image:
  13. Choose Review policy.
  14. Choose Save changes.

Setting Up the S3 Event

Now that the role has permissions to get files from the correct S3 bucket, you must set up an event on that bucket. This event triggers when new objects are placed in the bucket and executes the Lambda function that delivers the reports.

Next, let’s create that event.

  1. Open the S3 console.
  2. In the S3 console, find your bucket, and choose the bucket name.
  3. On the bucket detail page, choose the Properties tab.
  4. Scroll down to the Advanced settings section, and choose Events.
  5. In the Events window, choose Add notification.
  6. Give the notification a name, such as NewReportEvent.
  7. In the Events section, select the Put box.
  8. Leave all other checkboxes unchecked.
  9. In the Send to section, choose Lambda Function.
  10. In the Lambda drop down menu, choose the function that starts with ConnectReportsDistributor.
  11. Choose Save.

Everything is now set up and ready to handle your reports as they are exported. The last thing to do is schedule reports for delivery.

Scheduling Reports

To schedule a report, first create and save the report. If you have never created and saved a report in Amazon Connect, you can find detailed instructions in the Historical Metrics Reports section of the user guide. When scheduling reports, it is important to make sure to set the prefix. This allows the Lambda function to identify where the reports should be delivered.

To schedule a report:

  1. Log in to your instance using the administrator account, or an account that has permissions to create and schedule reports.
  2. In the left navigation pane, go to Metrics and quality, Saved reports.
  3. Choose Historical metrics.
  4. Hold the cursor over the line that contains the report that you want to schedule. Choose the clock icon that appears to the right of the report name.
  5. Configure the Recurrence that you want for this report. An example of an hourly report is displayed in the following image.
  6. Choose the Delivery Options tab.
  7. In the Prefix box, enter one of the SearchKey values that you provided when you ran the CloudFormation template, such as Sales or Service. When your report is saved to the S3 bucket, the Lambda function is triggered, which checks the name of the incoming file to see if it matches any of your search keys. If it does, the function then assigns the correct email distribution and sends the email. If it does not, the function sends the report to the default email address specified. You should see the file name example expand to include the prefix.
  8. Choose Create.

Setup is complete! When the scheduled report is generated, the output is saved to the S3 bucket. This triggers the event, calls the Lambda function, and ultimately sends the email to the appropriate recipients with the report attached.

Making Further Changes

This solution provides a foundation to build on. The Lambda function is written to filter for two different distributions with a third for the default delivery. If you want to add more groups or filters, add environment variables for the keys (search criteria) and the recipient group, then add the new recipient and filter to the if statement that determines which address to use. For example, to add a third category of “Contracts” which should send reports to the  email distribution of “”, perform the following:

  1. Open the AWS Lambda console.
  2. Choose the Lambda function that starts with ConnectReportsDistributor-LambdaFunction
  3. In the function code, find the comment # Grab all of our environment variables and assign them to local vars
  4. In try section that follows, find group_2 = os.environ[‘key_2’]
  5. Add the following code on a new line after that: group_3 = os.environ[‘key_3’]
  6. Next, find recipient_2 = os.environ[‘recipient_2’]
  7. Add the following code on a new line after that: recipient_3 = os.environ[‘recipient_3’]
  8. Now find the comment block that begins with # Then check it against our defined options
  9. Below the comment block, find clean_group_2 = group_2.lower()
  10. Add the following code on a new line after that: clean_group_3 = group_3.lower()
  11. Next, find elif clean_group_2 in sanitized_filename:
  12. After the recipient = recipient_2 line, add the following code on a new line: elif clean_group_3 in sanitized_filename:
  13. Then add a new indented line with: recipient = recipient_3
  14. Go to the Environment variables section
  15. Add a new key named key_3 with a value of Contracts
  16. Add another new key named recipient_3 with a value of
  17. Save the function

Repeat this process, incrementing the number appropriately, for each new group and distribution that you wish to use. For reference, you can download this modified version of the code.


In this blog post, you configured AWS services to deliver your scheduled reports from Amazon Connect to your users via email. You used CloudFormation to lay the groundwork, Amazon Connect to generate reports, IAM Roles to provide the security needed, S3 events to trigger the execution, and a Lambda function to prepare and send the email and attachment. This delivery mechanism provides your contact center managers with the data they need, when they need it, to provide outstanding customer service.