Code Monkey home page Code Monkey logo

amazon-connect-java-cdk's Introduction

amazon-connect-java-cdk

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.

Architecture

amazon-connect-java-cdk.drawio.png

Pre-requisites

Before getting started, make sure you have the following:

  • AWS Account

  • Java Development Kit (JDK) installed on your local machine

    • Java 11 or later. If missing install Amazon Corretto Java 11 from here.

      java -version
    • Maven 3.8 or later. If missing install Maven from here.

    • Note: Java version showed in the below output should be 11 or later.

      mvn -version
  • AWS CLI configured with valid credentials

    • AWS CLI. If missing install AWS CLI from here.
      aws --version
  • Node.js and npm installed (required for CDK)

    • Node.js 18.x or later. If missing install Node.js from here.
      node -v
  • 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>

Installation

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

Build

Run below build command from the root directory of the project.

mvn clean install

Deployment

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>

Verify

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. AWSCloudformation_Resources.png

Testing

Validate Amazon Connect Instance is created from AWS Management Console.

Cleanup

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.


Code Snippets

Refer to AmazonConnectStack.java for full stack code

Create Amazon Connect Instance:

        // 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:

        // Claim Phone Number for Amazon Connect Instance
        CfnPhoneNumber.Builder.create(this, "connect-example-phone-number")
                .countryCode("US")
                .targetArn(amazonConnect.getAttrArn())
                .type("TOLL_FREE")
                .build();

Access Existing Routing Profile ARN:

        // 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 Amazon Connect Hours of Operation:

        // 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();

Create Amazon Connect Queue:

        // 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();

Create Amazon Connect Routing Profile:

        // 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();

amazon-connect-java-cdk's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.