This snippet helps make a routing decision whether to add a new contact to the queue or take another action (like terminating the call) based on the queue length and the business hours for that day.
The solution includes 2 AWS Lambda functions, and an Amazon DynamoDB table:
-
UpdateQueueHours
Lambda function:- Triggered by AWS EventBridge scheduled rule
UpdateRate
parameter defines Hours of Operation refresh rate, between DynamoDB and Amazon Connect Instance- Retrieves all Queues from an Amazon Connect instance
- For each queue, retrieves the queue Hours of Operation
- Stores Queue and Hours of Operation configuration in a DynamoDB table
-
GetTimeLeft
Lambda function:- Triggered by Amazon Connect Contact Flow
- Receives contact's
Queue ARN
andOldest contact in queue
- Retrieves Queue and Hours of Operation configuration from the DynamoDB table
- Checks the Hours of Operation and determines
HoursOfOperationStatus
as:QUEUE_NOT_FOUND
- in case the Queue was not found in the DynamoDB tableOUT_OF_HOURS
- in case:current day
was not found in the Hours of Operation, orcurrent time
was outside ofStart
andEnd
time window for thecurrent day
OPEN_ALL_HOURS
- in caseStart
andEnd
time were equal for thecurrent day
IN_HOURS
- in casecurrent time
was betweenStart
andEnd
time window for thecurrent day
- Only if
HoursOfOperationStatus
wasIN_HOURS
, the function adds the following to the response:TimeLeftMinutes
= time difference betweencurrent time
andEnd
timeTimeDeltaMinutes
= time difference betweenTimeLeftMinutes
andOldest contact in queue
Based on GetTimeLeft
function response, you can design your Amazon Connect Contact Flow to either add the contact to the queue, if there was enough time left before the queue closes, or take another action.
To invoke GetTimeLeft
function from your Amazon Connect Contact Flow:
- Place
Set working queue
block and set your Queue (i.e. BasicQueue) - Place
Get queue metrics
block - Place
Invoke AWS Lambda function
and selectGetTimeLeft
Lambda function - In Lambda function input parameters add:
- Select
Use attribute
- Destination key:
OldestContactTimeSeconds
- Type:
Queue metrics
- Attribute:
Oldest contact in queue
- Select
- Place
Check contact attributes
and select Type:External
, Attribute:HoursOfOperationStatus
, then add conditions:QUEUE_NOT_FOUND
,OUT_OF_HOURS
,OPEN_ALL_HOURS
,IN_HOURS
, and complete the contact treatment based on the result. - For
IN_HOURS
result, you can add anotherCheck contact attributes
block to checkExternal
->TimeLeftMinutes
andExternal
->TimeDeltaMinutes
response parameters, then complete the contact treatment based on the result.
An AWS Serverless Application Model (SAM) defines the application's AWS resources in template.yaml
file.
The application includes AWS resources such as AWS Lambda functions, Amazon DynamoDB and Amazon CloudWatchEvents. You can update the template to add additional AWS resources, through the same deployment process that updates your application code.
If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit.
The AWS Toolkit is an open source plug-in for popular IDEs that uses the SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds a simplified step-through debugging experience for Lambda function code. See the following links to get started.
The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing serverless applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API.
To use the SAM CLI, you need the following tools.
- SAM CLI - Install the SAM CLI
- Python 3 installed
- Docker (for local testing only) - Install Docker community edition
To build and deploy your application for the first time, run the following in your shell:
sam build
sam deploy --guided
If you no longer need the AWS resources that you created by running this script, you can remove them by deleting the AWS CloudFormation stack that you deployed.
aws cloudformation delete-stack --stack-name <stack_name> --region <region>