Skip to content

How to call Amazon Connect Admin APIs in Lambda

This page shows how to create a Lambda function which can read data from the Amazon Connect Admin API and return it.

Example use cases

  • List all queues for a Connect instance to display to an admin user in a custom management interface
  • Script which can automatically update contact centre opening hours as they change towards peak season

Example: List all queues

In this example we will cover off how to return all queues for a Connect instance from a Lambda function.

01. Create Lambda function

Create a new Lambda function in the Lambda section of the AWS console:

  1. Click ‘Create new function’ and select ‘Author from scratch’.

  2. Give the function a name, select an appropriate runtime (we will be using NodeJS), create a new execution role for the function and click ‘Create function’.

  3. Add the following code to the function

    const AWS = require('aws-sdk');
    const connect = new AWS.Connect();
    
    const handler = async (event) => {
    
      let params = {
        InstanceId: 'YOUR_INSTANCE_ID',
        // MaxResults: 'NUMBER_VALUE',
        // NextToken: 'STRING_VALUE',
        // QueueTypes: [
        // "STANDARD", "AGENT", // etc
        // ]
      };
    
      let listQueues;
    
      try {
        listQueues = await connect.listQueues(params).promise();
      } catch (error) {
        console.log('error', error);
      }
    
      console.log('listQueues', JSON.stringify(listQueues));
    
      let result = {};
    
      if (listQueues?.QueueSummaryList) {
        console.log('success');
        result.success = true;
        result.queues = listQueues.QueueSummaryList;
    
      } else {
        console.log('error getting queues');
        result.success = false;
      }
    
      return result;
    };
    
    exports.handler = handler;
    

    This code takes advantage of the ListQueues API action and more specifically uses the Javascript SDK implementation of it.

02. Add Connect permissions to the execution role

  1. Find the role we created in the IAM section of the AWS Console (named ‘demo-lambda-listAllConnectQueues’ in the example above)

  2. Click ‘Attach policy’ and select ‘Create policy’. You can use the policy builder to select the Actions your Lambda function needs - in our case, it’s just ListQueues for one Connect instance.

    Set the correct Connect instance ARN in the ‘Resources’ section.

    Click ‘Next’, assign tags if required and click ‘Next’ again.

  3. Give the Policy a name, for example ‘demo-readConnectQueues’, a description and click ‘Create policy’.

  4. Attach the new policy to the role

03. Test the Lambda function

  1. Back on our Lambda function in the ‘Test’ dropdown, select ‘Configure test event’.

    Select ‘Connect Contact Flow’ from the sample events provided by AWS and give the test event a name, for example ‘Connect'.

    Click ‘Create’ to finish.

  2. Click ‘Test’ to execute the function with the test event we just created.

  3. Check the result in the ‘Execution result’ tab and you should see a list of the queues from the Connect instance.

    If the Connect instance has a large number of queues, you will need to paginate through the results using the NextToken field in the lambda function. It is also possible to filter the results by specific QueueTypes.