Automate Amazon Connect Data Streaming using AWS CDK
AWS Architecture BlogAutomate Amazon Connect Data Streaming using AWS CDKby Tarik Makota and Vaibhav Sabharwal | on04 FEB 2022| inAmazon Connect,Amazon Kinesis,Amazon Simple Storage Service (S3),Architecture,AWS Cloud Development Kit,AWS Identity and Access Management (IAM),AWS Lambda,Kinesis Data Firehose,Kinesis Data Streams|Permalink|ShareMany customers want to provisionAmazon Web Services (AWS)cloud resources quickly and consistently with lifecycle management, by treating infrastructure as code (IaC). Commonly used services areAWS CloudFormationand HashiCorpTerraform. Currently, customers set upAmazon Connectdata streaming manually, as the service is not available under CloudFormation resource types. Customers may want to extend it to retrieve real-time contact and agent data. Integration is done manually and can result in issues with IaC.Amazon Connect contact trace records (CTRs) capture the events associated with a contact in the contact center. Amazon Connect agent event streams areAmazon Kinesis Data Streamsthat provide near real-time reporting of agent activity within the Amazon Connect instance. The events published to the stream include these contact control panel (CCP) events:Agent loginAgent logoutAgent connects with a contactAgent status change, such as toavailable to handle contacts, oron break, orat training.In this blog post, we will show you how to automate Amazon Connect data streaming usingAWS Cloud Development Kit (AWS CDK). AWS CDK is an open source software development framework to define your cloud application resources using familiar programming languages. We will create a custom CDK resource, which in turn uses Amazon Connect API. This can be used as a template to automate other parts of Amazon Connect, or for other AWS services that don’t expose its full functionality through CloudFormation.Overview of Amazon Connect automation solutionAmazon Connect is an omnichannel cloud contact center that helps you provide superior customer service. We will stream Amazon Connect agent activity and contact trace records toAmazon Kinesis. We will assume that data will then be used by other services or third-party integrations for processing. Here are the high-level steps and AWS services that we are going use, see Figure 1:Amazon Connect:We will create an instance and enable data streamingCloud Deployment Toolkit:We will create custom resource and orchestrate automationAmazon Kinesis Data Streams andAmazon Kinesis Data Firehose:To stream data out of ConnectAWS Identity and Access Management (IAM):To govern access and permissible actions across all AWS servicesThird-party tool orAmazon S3:Used as a destination of Connect data via Amazon Kinesis dataFigure 1. Connect data streaming automation workflowWalkthrough and deployment tasksSample code for this solution is provided in thisGitHub repo. The code is packaged as a CDK application, so the solution can be deployed in minutes. The deployment tasks are as follows:Deploy the CDK appUpdate Amazon Connect instance settingsImport the demo flow and dataCustom Resourcesenables you to write custom logic in your CloudFormation deployment. You implement the creation, update, and deletion logic to define the custom resource deployment.CDK implements theAWSCustomResource, which is anAWS Lambdabacked custom resource that uses the AWS SDK to provision your resources. This means that the CDK stack deploys aprovisioning Lambda. Upon deployment, it calls the AWS SDK API operations that you defined for the resource lifecycle (create, update, and delete).PrerequisitesFor this walkthrough, you need the following prerequisites:AnAWS account.This post uses an AWS CDK stack written in Python; follow the instructions in theCDK Getting Startedguide to set up your environment.An Amazon Connect instance. If you do not have one, you can deploy a Connect instance and claim a phone number, seeSet up your Amazon Connect instance.Deploy and verify1. Deploy the CDK application.The resources required for this demo are packaged as a CDK app. Before proceeding, confirm you have command line interface (CLI) access to the AWS account where you would like to deploy your solution.Open a terminal window and clone the GitHub repository in a directory of your choice:git clone git@github.com:aws-samples/connect-cdk-blogNavigate to the cdk-app directory and follow the deployment instructions. The default Region is usually us-east-1. If you would like to deploy in another Region, you can run:export AWS_DEFAULT_REGION=eu-central-12. Create the CloudFormation stack by initiating the following commands.source .env/bin/activatepip install -r requirements.txtcdk synthcdk bootstrapcdk deploy  --parametersinstanceId={YOUR-AMAZON-CONNECT-INSTANCE-ID}--parameters ctrStreamName={CTRStream}--parameters agentStreamName={AgentStream}Note:By default, the stack will create contact trace records stream [ctrStreamName] as a Kinesis Data Stream. If you want to use an Amazon Kinesis Data Firehose delivery stream instead, you can modify this behavior by going to cdk.json and adding “ctr_stream_type”: “KINESIS_FIREHOSE” as a parameter under “context.”Once the status of CloudFormation stack is updated to CREATE_COMPLETE, the following resources are created:Kinesis Data StreamIAM rolesLambda3. Verify the integration.Kinesis Data Streams are added to the Amazon Connect instanceFigure 2. Screenshot of Amazon Connect with Data Streaming enabledCleaning upYou can remove all resources provisioned for the CDK app by running the following command under connect-app directory:cdk destroyThis willnotremove your Amazon Connect instance. You can remove it by navigating to theAWS Management Console-> Services -> Amazon Connect. Find your Connect instance and click Delete.ConclusionIn this blog, we demonstrated how to maintain Amazon Connect as Infrastructure as Code (IaC). Using a custom resource of AWS CDK, we have shown how to automate setting Amazon Kinesis Data Streams to Data Streaming in Amazon Connect. The same approach can be extended to automate setting other Amazon Connect properties such asAmazon Lex, AWS Lambda,Amazon Polly, andCustomer Profiles. This approach will help you to integrate Amazon Connect with your Workflow Management Application in a faster and consistent manner, and reduce manual configuration.For more information, refer toEnable Data Streaming for your instance.Tarik MakotaTarik Makota is a Principal Solutions Architect with Amazon Web Services. He provides technical guidance, design advice, and thought leadership to AWS’ customers across the US Northeast. He holds an M.S. in Software Development and Management from Rochester Institute of Technology.Vaibhav SabharwalVaibhav Sabharwal is a Senior Customer Solutions Manager with Amazon Web Services. Vaibhav helps AWS’ customers to build cloud adoption strategy, design innovative solutions, and drive operational excellence.
Many customers want to provision Amazon Web Services (AWS) cloud resources quickly and consistently with lifecycle management, by treating infrastructure as code (IaC). Commonly used services are AWS CloudFormation and HashiCorp Terraform. Currently, customers set up Amazon Connect data streaming manually, as the service is not available under CloudFormation resource types. Customers may want to […]
Tarik Makota
Amazon Connect Amazon Kinesis Amazon Simple Storage Service (S3) Architecture AWS Cloud Development Kit AWS Identity and Access Management (IAM) AWS Lambda Kinesis Data Firehose Kinesis Data Streams