This repository provides an example of deploying an Amazon Connect instance using the AWS Cloud Development Kit (CDK) and Java. Amazon Connect is a cloud-based contact center service provided by Amazon Web Services (AWS). With the help of CDK, you can provision and manage your Amazon Connect resources using infrastructure-as-code principles.
Before getting started, make sure you have the following:
-
AWS Account
-
Java Development Kit (JDK) installed on your local machine
-
AWS CLI configured with valid credentials
- AWS CLI. If missing install AWS CLI from here.
aws --version
- AWS CLI. If missing install AWS CLI from here.
-
Node.js and npm installed (required for CDK)
- Node.js 18.x or later. If missing install Node.js from here.
node -v
- Node.js 18.x or later. If missing install Node.js from here.
-
AWS CDK - Install the AWS CDK Toolkit globally using the following command:
npm install -g aws-cdk
cdk --version
- CDK Bootstrap - Bootstrap your AWS account for CDK. This only needs to be done once per account/region.
cdk bootstrap aws://<account>/<region>
- CDK Bootstrap - Bootstrap your AWS account for CDK. This only needs to be done once per account/region.
Clone this repository and navigate to the project directory.
git clone https://github.com/aws-samples/amazon-connect-java-cdk.git
cd amazon-connect-java-cdk
Run below build command from the root directory of the project.
mvn clean install
Change to the Infra directory of the project.
cd Infra
Quick deployment: This will deploy the application with default options for parameters connectInstanceAlias
Run the below command to deploy the application.
cdk deploy
Custom deployment: Pass your values to the parameters.
Run the below command to deploy the application.
cdk deploy --no-previous-parameters --parameters connectInstanceAlias=<Unique Alias>
Make sure you are in the right AWS account and region.
AWS CloudFormation will create similar to below resources
Note: Not all the resources are shown in the screenshot below.
Validate Amazon Connect Instance is created from AWS Management Console.
Run the below command to delete the application.
cdk destroy
This will delete the provisioned Amazon Connect instance and any related resources from your AWS account.
Refer to AmazonConnectStack.java
for full stack code
// Amazon Connect Instance
CfnInstance amazonConnect = CfnInstance.Builder.create(this, "connect-example")
.instanceAlias(connectInstanceAlias.getValueAsString())
.attributes(CfnInstance.AttributesProperty.builder()
.autoResolveBestVoices(true)
.contactflowLogs(true)
.contactLens(true)
.inboundCalls(true)
.outboundCalls(true)
.build())
.identityManagementType(userMgmtType.getValueAsString())
.build();
// Claim Phone Number for Amazon Connect Instance
CfnPhoneNumber.Builder.create(this, "connect-example-phone-number")
.countryCode("US")
.targetArn(amazonConnect.getAttrArn())
.type("TOLL_FREE")
.build();
// API Call to get Routing Profile ARN
AwsSdkCall listRoutingProfiles = AwsSdkCall.builder()
.service("Connect")
.action("listRoutingProfiles")
.parameters(Map.of("InstanceId", amazonConnect.getAttrId()))
.physicalResourceId(PhysicalResourceId.of("CustomProviderListRoutingProfiles"))
.build();
AwsCustomResource awsCustomResourceListRoutingProfiles = AwsCustomResource.Builder.create(this, "CustomProviderListRoutingProfiles ")
.onCreate(listRoutingProfiles)
.policy(AwsCustomResourcePolicy.fromSdkCalls(SdkCallsPolicyOptions.builder()
.resources(AwsCustomResourcePolicy.ANY_RESOURCE)
.build()))
.build();
String routingProfileARN = awsCustomResourceListRoutingProfiles.getResponseField("RoutingProfileSummaryList.0.Arn");
// Create Hours of Operation Config for Escalation Queue from 8am to 5pm
ArrayList<CfnHoursOfOperation.HoursOfOperationConfigProperty> dayConfigs = new ArrayList<>();
List.of("MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY").forEach(day -> {
dayConfigs.add(CfnHoursOfOperation.HoursOfOperationConfigProperty.builder()
.day(day)
.startTime(CfnHoursOfOperation.HoursOfOperationTimeSliceProperty.builder()
.hours(8)
.minutes(0)
.build())
.endTime(CfnHoursOfOperation.HoursOfOperationTimeSliceProperty.builder()
.hours(17)
.minutes(0)
.build())
.build());
});
// Create Hours of Operation
CfnHoursOfOperation cfnHoursOfOperation = CfnHoursOfOperation.Builder.create(this, "amazon-connect-hours-of-operation")
.name("Escalation Hours of Operation")
.description("This Hours of Operation is used for Escalation and open weekdays from 8am to 5pm")
.instanceArn(amazonConnect.getAttrArn())
.timeZone("US/Pacific")
.config(dayConfigs)
.build();
// Amazon Connect Create new Queue
CfnQueue escalationQueue = CfnQueue.Builder.create(this, "amazon-connect-escalation-queue")
.description("This Queue is used for Escalation")
.instanceArn(amazonConnect.getAttrArn())
.name("EscalationQueue")
.outboundCallerConfig(CfnQueue.OutboundCallerConfigProperty.builder()
.outboundCallerIdName("AnyCompanyPrioritySupport")
.outboundCallerIdNumberArn(cfnPhoneNumber.getAttrPhoneNumberArn())
.build())
.hoursOfOperationArn(cfnHoursOfOperation.getAttrHoursOfOperationArn())
.build();
// Amazon Connect Create new Routing Profile
CfnRoutingProfile.Builder.create(this, "amazon-connect-routing-profile")
.description("This Routing Profile is used for Escalation")
.instanceArn(amazonConnect.getAttrArn())
.name("EscalationRoutingProfile")
.defaultOutboundQueueArn(escalationQueue.getAttrQueueArn())
.queueConfigs(List.of(CfnRoutingProfile.RoutingProfileQueueConfigProperty.builder()
.priority(1)
.queueReference(CfnRoutingProfile.RoutingProfileQueueReferenceProperty.builder()
.queueArn(escalationQueue.getAttrQueueArn())
.channel("VOICE")
.build())
.delay(0)
.build()))
.mediaConcurrencies(List.of(
CfnRoutingProfile.MediaConcurrencyProperty.builder()
.channel("VOICE")
.concurrency(1)
.build(),
CfnRoutingProfile.MediaConcurrencyProperty.builder()
.channel("CHAT")
.concurrency(3)
.build()))
.build();