

# Step 1: Prepare your Connect Customer instance

In this step, you prepare the test Connect Customer instance for the guide and for a test chat. Do these tasks in order:

1. If you don't have a test instance, create one.

1. Enable Connect Customer on the instance.

1. Check the instance.

1. Create the test agent and its Modern layout, with the test setup script (recommended) or in the Connect Customer admin website.

1. Give your security profile the permissions to edit the guide's flows.

Several tasks use the Connect Customer admin website. To open it, do one of the following:
+ In the AWS Management Console, search for **Connect Customer** and choose it, choose the instance alias, and choose **Log in for emergency access**. Use emergency access on the test instance; in production, sign in as a named user.
+ Open the instance's access URL, which the check in this step prints, and sign in with your Connect Customer user.

## Create a test instance
<a name="real-time-data-integration-instance-create"></a>

**To create a test instance**

1. Follow [Create a Connect Customer instance](https://docs.aws.amazon.com/connect/latest/adminguide/amazon-connect-instances.html) in the Connect Customer console, in a Region from the prerequisites.

1. Choose **Store users in Amazon Connect**.

1. In **Add administrator**, choose **Specify an administrator**, so that you can sign in to the admin website as that user.

1. To test with calls, keep **Allow incoming calls** selected in the telephony options. You claim a test phone number in Step 4.

## Enable Connect Customer on the instance
<a name="real-time-data-integration-instance-enable"></a>

The External Tool block, which the guide uses to call the gateway, works only on an instance with Connect Customer enabled. Without it, the stack fails to deploy. An instance created before Connect Customer was available might need to be updated to it. The change applies at once and also sets the plan that the External Tool block needs; no API sets it.

**To enable Connect Customer on the instance**

1. In the AWS Management Console, search for **Connect Customer** and choose it, then choose the instance alias.

1. In the navigation pane, choose **Customer**. If the **Confirm Amazon Connect Customer** section shows **Amazon Connect Customer Basic**, choose **Change**. It doesn't ask you to confirm.

   If the navigation pane shows **Connect Customer** instead, and the **Enable Connect Customer across your entire instance** section shows **Not enabled**, choose **Enable**.

The check that follows prints `Connect Customer plan (must be true): true` when the instance is ready. See [Enable Connect Customer](https://docs.aws.amazon.com/connect/latest/adminguide/enable-nextgeneration-amazonconnect.html). For pricing, see [Connect Customer pricing](https://aws.amazon.com/connect/pricing/).

## Check the instance
<a name="real-time-data-integration-instance-check"></a>

The check confirms that your AWS CLI has the commands this guide uses, that the instance is on Connect Customer, and that it uses a service-linked role, which the integration needs. It also prints the instance's ARN and access URL, its Connect assistant, and its queues with their ARNs, which you enter when you deploy the stack in Step 3. It changes nothing.

**To check the instance**

1. Sign in to the AWS Management Console, open [https://console.aws.amazon.com/cloudshell/home](https://console.aws.amazon.com/cloudshell/home), and in the Region selector in the navigation bar, choose your instance's Region. If CloudShell isn't available in that Region, it opens in a nearby Region; type your instance's Region at the prompt in the next step. To use your computer instead, see [Where to run the AWS commands](real-time-data-integration-setup.md#real-time-data-integration-where-to-run).

1. Expand the instance check script, copy it, paste it at the prompt, and press Enter. It asks for the Region and the instance alias. If the default Region in brackets isn't your instance's Region, type your instance's Region at the prompt. When the Region has more than one instance, the alias has no default: type it from the list.

### The instance check script
<a name="real-time-data-integration-code-instance-check-script"></a>

```
(
  R=${AWS_REGION:-us-east-1}
  printf 'Region of your Connect Customer instance [%s]: ' "$R"; read -r REGION; REGION=${REGION:-$R}
  echo "AWS CLI: $(aws --version 2>&1 | cut -d' ' -f1)"
  if AC=$(aws bedrock-agentcore-control list-gateways --region "$REGION" --max-results 1 2>&1 >/dev/null); then
    echo "AgentCore commands: ok"
  else
    case "$AC" in
      *"nvalid choice"*) echo "AgentCore commands: missing; update the AWS CLI" ;;
      *AccessDenied*) echo "AgentCore commands: ok, but your IAM identity can't list gateways" ;;
      *) echo "AgentCore commands: failed: $AC" ;;
    esac
  fi
  ACCOUNT=$(aws sts get-caller-identity --region "$REGION" --query Account --output text) || exit 1
  echo "AWS account: $ACCOUNT"
  ALIASES=$(aws connect list-instances --region "$REGION" --query 'InstanceSummaryList[].InstanceAlias' --output text) || exit 1
  ALIASES=$(echo "$ALIASES" | tr '\t' '\n' | grep .)
  [ -n "$ALIASES" ] || { echo "No Connect Customer instances in $REGION. Check the Region."; exit 1; }
  echo "Connect Customer instances in $REGION:"; echo "$ALIASES" | sed 's/^/  /'
  if [ "$(echo "$ALIASES" | wc -l)" -eq 1 ]; then
    printf 'Instance alias [%s]: ' "$ALIASES"; read -r ALIAS; ALIAS=${ALIAS:-$ALIASES}
  else
    printf 'Instance alias, typed from the list (there is no default): '; read -r ALIAS
  fi
  [ -n "$ALIAS" ] || { echo "No instance alias entered; nothing was changed."; exit 1; }
  ID=$(aws connect list-instances --region "$REGION" --query "InstanceSummaryList[?InstanceAlias=='$ALIAS'].Id" --output text | grep -m 1 .)
  [ -n "$ID" ] || { echo "No instance named $ALIAS in $REGION. Check the Region and the alias."; exit 1; }
  echo "Connect Customer plan (must be true): $(aws connect describe-instance-attribute --region "$REGION" --instance-id "$ID" \
    --attribute-type MAX_PACKAGE --query Attribute.Value --output text)"
  echo "Connect instance ARN: $(aws connect describe-instance --region "$REGION" --instance-id "$ID" --query Instance.Arn --output text)"
  URL=$(aws connect describe-instance --region "$REGION" --instance-id "$ID" --query Instance.InstanceAccessUrl --output text)
  echo "Connect instance access URL: ${URL%/}"
  echo "Service role (must contain aws-service-role): $(aws connect describe-instance --region "$REGION" --instance-id "$ID" --query Instance.ServiceRole --output text)"
  ASSISTANT=$(aws connect list-integration-associations --region "$REGION" --instance-id "$ID" --integration-type WISDOM_ASSISTANT \
    --query 'IntegrationAssociationSummaryList[0].IntegrationArn' --output text)
  case "$ASSISTANT" in arn:*) ;; *) ASSISTANT=none ;; esac
  echo "Connect assistant (Existing Connect assistant field): $ASSISTANT"
  echo "Queues, each with its ARN (for Test queue ARN, if you create the test agent in the admin website):"
  aws connect list-queues --region "$REGION" --instance-id "$ID" --queue-types STANDARD \
    --query 'QueueSummaryList[].[Name,Arn]' --output text | sed 's/^/  /'
)
```

It prints the AWS CLI version, `AgentCore commands: ok`, your account ID, your instances, `Connect Customer plan (must be true): true`, the instance's ARN and access URL, its service role, its Connect assistant's ARN or `none`, and its queues with their ARNs. Keep this output: Step 3 uses the ARN, the access URL and the Connect assistant line, and Step 4 uses the access URL. If you create the test agent in the admin website rather than with the test setup script, Step 3 also uses the ARN of the test agent's queue from this list. To print the values again, run the block again. If it prints something else:
+ `AgentCore commands: ok, but your IAM identity can't list gateways`: the CLI has the gateway commands, but your identity lacks `bedrock-agentcore:ListGateways`. The stack still deploys if your identity can create the stack's resources; see [CloudFormation template reference](real-time-data-integration-deployment.md) for the permissions.
+ `AgentCore commands: missing`: the AWS CLI is older than the gateway commands. In CloudShell, close and reopen it; on your computer, update the AWS CLI. See [Installing or updating to the latest version of the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html).
+ `Service role (must contain aws-service-role)` without `aws-service-role`: the instance doesn't use a service-linked role. See [Use service-linked roles for Connect Customer](https://docs.aws.amazon.com/connect/latest/adminguide/connect-slr.html).
+ An `AccessDeniedException`: your IAM identity can't read Connect Customer instances. Ask your AWS administrator for read access to Connect Customer.
+ `No instance named`: the instance is in another Region, or the alias is misspelled. Run the block again with the Region that the instance's ARN shows.
+ `Connect Customer plan (must be true): false`: enable Connect Customer on the instance, as [Enable Connect Customer on the instance](#real-time-data-integration-instance-enable) describes, and run the block again.

## Create the test agent and its Modern layout
<a name="real-time-data-integration-instance-agent"></a>

The test agent is the Connect Customer user who accepts the test chat or test call in Step 4. It needs a queue, a routing profile, a security profile, a user and a Modern workspace, none of which changes what your other agents have. The test setup script creates all five in one run; to create them yourself, use the admin website steps.

------
#### [ Test setup script (recommended) ]

The test setup script creates these resources:

1. The queue `rtdi-test-queue`, on **Basic Hours** or the instance's first hours of operation. The stack's inbound flow sends test chats and test calls there. You enter its ARN as **Test queue ARN** when you deploy the stack in Step 3.

1. The routing profile `rtdi-test-routing`, which takes one chat at a time from that queue.

1. The security profile `rtdi-test-agent`, with **Access Contact Control Panel - Access**, **Custom views - Access**, **Connect assistant - View** and **Views - View**, and the permission to run flow modules as tools, which the admin website grants when you select a module under **Flow modules**.

1. The test agent's user.

1. The workspace `rtdi-modern`, with the Modern layout of the agent workspace, visible only to the test agent. An agent who has no workspace assigned sees the original layout.

It tags everything it creates with `rtdi-test-setup`. When you run it again, it reuses what it created. If a queue, profile, user or workspace with one of these names exists and the script didn't create it, the script stops and changes nothing. **remove** deletes what it created.

**To create the test resources with a script**

1. Expand *The test setup script*, which follows these tabs, copy it, paste it at the prompt, and press Enter; it asks for your instance's Region. Or save it as `test-setup.sh` and run **bash test-setup.sh**.

1. Press Enter to accept each default: the Region, **create**, the instance alias, which is the default when the Region has only one instance (with more than one, type the alias from the list), and the username **rtdi-test-agent**.

   If your instance signs users in through SAML or a directory, the script says so. It then asks for the username of a user who exists in your identity provider or directory and isn't yet a Connect Customer user.

1. If the script asks for a password, enter one for the test agent at the `input hidden` prompt: 8 to 64 characters, with an uppercase letter, a lowercase letter and a number. It asks only when it creates a user on an instance that stores passwords in Connect Customer.

The test agent is ready when the script prints `DONE: the test agent is ready.`, a `Test queue ARN` line and the agent workspace URL. Keep the `Test queue ARN` line for Step 3. If the script prints `NOT DONE`, add the Modern page in the admin website as the line says. If it prints `STOPPED`, see [Testing in the agent workspace](real-time-data-integration-troubleshoot.md#real-time-data-integration-troubleshoot-agent).

The script's routing profile takes chats only. To test with calls, add calls to it in the admin website:

**To add calls to the test routing profile**

1. Choose **Users**, **Routing profiles**, and **rtdi-test-routing**.

1. In **Channel Settings**, select **Voice**.

1. In **Queues**, select the voice channel for `rtdi-test-queue`, and choose **Save**. See [Create a routing profile in Connect Customer to link queues to agents](routing-profiles.md).

------
#### [ Connect Customer admin website ]

Make the test agent's changes in a routing profile and security profile of its own. A change to the shared **Basic Routing Profile** or **Agent** security profile applies to every agent who has it. For the workspace, your security profile needs the **Workspaces** permissions **View**, **Create**, **Edit**, **Delete**, **Assign** and **Edit visibility**.

**To create the test resources in the admin website**

1. Choose **Routing**, **Queues**, **Add new queue**. Name it **rtdi-test-queue**, choose an hours of operation such as **Basic Hours**, and choose **Add new queue**. Then run the check again, and copy the queue's ARN from its list of queues. See [Create a queue using the Connect Customer admin website](create-queue.md).

1. Choose **Users**, **Routing profiles**, and **Add new profile**. Name it, for example **rtdi-test-routing**. In **Channel Settings**, select **Chat**, and **Voice** to test with calls. In **Queues**, add the test queue with the chat channel, and the voice channel to test with calls, and choose **Save**. See [Create a routing profile in Connect Customer to link queues to agents](routing-profiles.md).

1. Choose **Users**, **Security profiles**, and **Add security profile**. Name it, for example **rtdi-test-agent**. In **Contact Control Panel (CCP)**, select **Access Contact Control Panel - Access**. In **Agent Applications**, select **Custom views - Access** and **Connect assistant - View**. In **Channels and flows**, select **View** for **Views**. Choose **Save**. See [Create a security profile in Connect Customer](create-security-profile.md).

1. Choose **Users**, **User management**. To use an existing user, open it; otherwise choose **Add new users** and enter a name, a login and a password. Choose the test routing profile and the test security profile, and choose **Save**. The emergency access session can't be the test agent, because it isn't listed in **User management**. See [Add users to Connect Customer](user-management.md).

1. Create the Modern workspace:

   1. Choose **UI Management**, **Workspaces**, and **Add new workspace**. Enter a name, and choose **Save**.

   1. In the **Pages** section, choose **Add page** and **Use existing Connect page**. For **Page**, choose **Agent Workspace**; for **Page layout**, **Agent Workspace - Modern**; and for **View version**, **1**. Choose **Save**.

   1. In the **Assignments** section, choose **Visible to assigned users**, then **Add assignments**. Under **Users**, choose the test agent, and choose **Save**. Assign the workspace to the user, not to a routing profile: a routing profile assignment changes the layout for every agent in that routing profile.

The test agent is ready when **User management** lists the user with the test routing profile and the test security profile, and the workspace's **Assignments** section lists the user.

------

After you deploy the stack, you add the flow modules agent assist runs to the test security profile; see [Give agents agent assist in the agent workspace](real-time-data-integration-ai-assist.md).

### The test setup script
<a name="real-time-data-integration-code-test-setup-script"></a>

```
(
  set -uo pipefail
  TAG=rtdi-test-setup
  ask() { local reply; read -r -p "$1 [$2]: " reply; printf '%s' "${reply:-$2}"; }
  say() { printf '%-8s %s\n' "$1" "$2"; }
  stop() { echo "STOPPED: $1"; exit 1; }
  # The AWS CLI applies --query to each page of a list, so a lookup filters, and the first non-empty line is the match.
  first() { grep -m 1 . || true; }

  REGION=$(ask "Region of your Connect Customer instance" "${AWS_REGION:-us-east-1}")
  ACTION=$(ask "create (set up the test resources) or remove (delete them)" "create")
  case "$ACTION" in create|remove) ;; *) stop "type create or remove." ;; esac
  c() { aws connect "$@" --region "$REGION"; }

  echo "Connect Customer instances in $REGION:"
  ALIASES=$(c list-instances --query 'InstanceSummaryList[].InstanceAlias' --output text) || stop "couldn't list instances in $REGION; see the error above."
  ALIASES=$(echo "$ALIASES" | tr '\t' '\n' | grep . || true)
  [ -n "$ALIASES" ] || stop "no instances in $REGION. Check the Region."
  echo "$ALIASES" | sed 's/^/  /'
  if [ "$(echo "$ALIASES" | wc -l)" -eq 1 ]; then
    ALIAS=$(ask "Instance alias" "$ALIASES")
  else
    read -r -p "Instance alias, typed from the list (there is no default): " ALIAS
  fi
  [ -n "$ALIAS" ] || stop "no instance alias entered."
  ID=$(c list-instances --query "InstanceSummaryList[?InstanceAlias=='$ALIAS'].Id" --output text) || stop "couldn't list instances in $REGION; see the error above."
  ID=$(echo "$ID" | first)
  [ -n "$ID" ] || stop "no instance named $ALIAS in $REGION."
  ARN_BASE="" IDM=""
  read -r ARN_BASE IDM < <(c describe-instance --instance-id "$ID" --query 'Instance.[Arn,IdentityManagementType]' --output text)
  case "$ARN_BASE" in arn:*) ;; *) stop "couldn't read the instance $ALIAS; see the error above." ;; esac
  PARTITION=${ARN_BASE#arn:}; PARTITION=${PARTITION%%:*}

  if [ "$IDM" = CONNECT_MANAGED ]; then
    USERNAME=$(ask "Test agent's username" "rtdi-test-agent")
  else
    echo "This instance signs users in through $IDM, so the test agent has no password in Connect Customer."
    USERNAME=$(ask "Username of a user in your identity provider or directory who isn't yet a Connect Customer user" "")
    [ -n "$USERNAME" ] || stop "enter the username of a user that exists in your identity provider or directory."
  fi

  # With remove, a failed read is counted and the script carries on; with create, it stops.
  SOFT=no FAILED=0
  failed() {
    [ "$SOFT" = yes ] || stop "$1"
    echo "Failed   $1"; FAILED=$((FAILED + 1))
  }
  # lookup TYPE LIST-COMMAND...: sets FID and FARN to the resource the filter matches, None if there is none,
  # or Error if the list failed during remove.
  lookup() {
    local type=$1 out line; shift
    FID=None FARN=None
    out=$(c "$@" --output text) || { failed "couldn't read $type in $ALIAS; see the error above."; FID=Error; return; }
    line=$(echo "$out" | first)
    [ -z "$line" ] || read -r FID FARN <<< "$line"
  }
  queue() { lookup queues list-queues --instance-id "$ID" --queue-types STANDARD --query "QueueSummaryList[?Name=='$1'].[Id,Arn]"; }
  routing() { lookup "routing profiles" list-routing-profiles --instance-id "$ID" --query "RoutingProfileSummaryList[?Name=='$1'].[Id,Arn]"; }
  profile() { lookup "security profiles" list-security-profiles --instance-id "$ID" --query "SecurityProfileSummaryList[?Name=='$1'].[Id,Arn]"; }
  user() { lookup users list-users --instance-id "$ID" --query "UserSummaryList[?Username=='$1'].[Id,Arn]"; }
  workspace() { lookup workspaces list-workspaces --instance-id "$ID" --query "WorkspaceSummaryList[?Name=='$1'].[Id,Arn]"; }
  # ours TYPE: sets OURS to yes if this script created the resource FARN, from the tag it adds to everything it creates,
  # or to Error if the tags couldn't be read during remove.
  ours() {
    local value
    value=$(c list-tags-for-resource --resource-arn "$FARN" --query "tags.\"$TAG\"" --output text) \
      || { failed "couldn't read the tags of the $1 in $ALIAS; see the error above."; OURS=Error; return; }
    OURS=no; [ "$value" = true ] && OURS=yes
  }
  # mine TYPE NAME: stops if FID exists but this script didn't create it, so the script changes nothing.
  mine() {
    [ "$FID" = None ] && return 0
    ours "$1"
    [ "$OURS" = yes ] || stop "the $1 $2 already exists and this script didn't create it, so the script leaves it alone. Nothing was changed."
  }

  if [ "$ACTION" = remove ]; then
    OK=$(ask "Delete the test resources that this script created in $ALIAS, and the user $USERNAME? yes or no" "no")
    [ "$OK" = yes ] || { echo "Nothing was deleted."; exit 0; }
    SOFT=yes
    # gone TYPE NAME DELETE-COMMAND...: deletes the resource FID if this script created it.
    gone() {
      local type=$1 name=$2; shift 2
      [ "$FID" != Error ] || return 0
      if [ "$FID" = None ]; then say Skipped "$type $name: not found"; return; fi
      ours "$type"
      [ "$OURS" != Error ] || return 0
      if [ "$OURS" != yes ]; then say Skipped "$type $name: not created by this script"; return; fi
      if c "$@" "$FID"; then say Deleted "$type $name"; else failed "couldn't delete the $type $name; see the error above."; fi
    }
    workspace rtdi-modern; gone workspace rtdi-modern delete-workspace --instance-id "$ID" --workspace-id
    user "$USERNAME"; gone user "$USERNAME" delete-user --instance-id "$ID" --user-id
    profile rtdi-test-agent; gone "security profile" rtdi-test-agent delete-security-profile --instance-id "$ID" --security-profile-id
    routing rtdi-test-routing; gone "routing profile" rtdi-test-routing delete-routing-profile --instance-id "$ID" --routing-profile-id
    queue rtdi-test-queue; gone queue rtdi-test-queue delete-queue --instance-id "$ID" --queue-id
    [ "$FAILED" -eq 0 ] || { echo "NOT DONE: $FAILED resources weren't deleted; fix the error above and run remove again."; exit 1; }
    echo "DONE. Your other users and every resource this script did not create are unchanged."
    exit 0
  fi

  # Every name is checked before anything is created, so the script changes nothing if a name belongs to someone else.
  user "$USERNAME"; U=$FID UARN=$FARN
  if [ "$U" != None ]; then
    ours user
    [ "$OURS" = yes ] || stop "the user $USERNAME already exists and this script didn't create it, so the script leaves it alone. Run it again with a new username."
  fi
  queue rtdi-test-queue; mine queue rtdi-test-queue
  routing rtdi-test-routing; mine "routing profile" rtdi-test-routing
  profile rtdi-test-agent; mine "security profile" rtdi-test-agent
  workspace rtdi-modern; mine workspace rtdi-modern
  PW=""
  if [ "$U" = None ] && [ "$IDM" = CONNECT_MANAGED ]; then
    IFS= read -r -s -p "Password for $USERNAME, 8 to 64 characters with an uppercase letter, a lowercase letter and a number (input hidden): " PW; echo
    { [ ${#PW} -ge 8 ] && [ ${#PW} -le 64 ] && [[ "$PW" =~ [A-Z] ]] && [[ "$PW" =~ [a-z] ]] && [[ "$PW" =~ [0-9] ]]; } \
      || stop "the password needs 8 to 64 characters, with an uppercase letter, a lowercase letter and a number. Nothing was created."
    [[ ! "$PW" =~ [[:cntrl:]] ]] || stop "the password can't contain tabs or other control characters. Nothing was created."
  fi

  # 1. The test queue, rtdi-test-queue, on the instance's Basic Hours or its first hours of operation.
  queue rtdi-test-queue; Q=$FID QARN=$FARN
  if [ "$Q" != None ]; then say Reused "queue rtdi-test-queue"
  else
    H=$(c list-hours-of-operations --instance-id "$ID" --query "HoursOfOperationSummaryList[?Name=='Basic Hours'].Id" --output text) \
      || stop "couldn't read hours of operation in $ALIAS; see the error above."
    H=$(echo "$H" | first)
    if [ -z "$H" ]; then
      H=$(c list-hours-of-operations --instance-id "$ID" --query 'HoursOfOperationSummaryList[].Id' --output text) \
        || stop "couldn't read hours of operation in $ALIAS; see the error above."
      H=$(echo "$H" | tr '\t' '\n' | first)
    fi
    [ -n "$H" ] || stop "the instance has no hours of operation for the test queue."
    Q="" QARN=""
    read -r Q QARN < <(c create-queue --instance-id "$ID" --name rtdi-test-queue --description "Test queue for real-time data integration" \
      --hours-of-operation-id "$H" --tags "$TAG=true" --query '[QueueId,QueueArn]' --output text)
    [ -n "$Q" ] || stop "couldn't create the queue rtdi-test-queue."
    say Created "queue rtdi-test-queue"
  fi

  # 2. The routing profile: chat from the test queue, one chat at a time.
  routing rtdi-test-routing; RP=$FID
  if [ "$RP" != None ]; then say Reused "routing profile rtdi-test-routing"
  else
    RP=$(c create-routing-profile --instance-id "$ID" --name rtdi-test-routing \
      --description "Test agent for real-time data integration" --default-outbound-queue-id "$Q" \
      --media-concurrencies Channel=CHAT,Concurrency=1 \
      --tags "$TAG=true" --query RoutingProfileId --output text) || stop "couldn't create the routing profile rtdi-test-routing."
    say Created "routing profile rtdi-test-routing"
  fi
  HAVE=$(c list-routing-profile-queues --instance-id "$ID" --routing-profile-id "$RP" \
    --query "RoutingProfileQueueConfigSummaryList[?QueueId=='$Q' && Channel=='CHAT'].QueueId" --output text) \
    || stop "couldn't read the queues of rtdi-test-routing in $ALIAS; see the error above."
  if [ -z "$(echo "$HAVE" | first)" ]; then
    c associate-routing-profile-queues --instance-id "$ID" --routing-profile-id "$RP" \
      --queue-configs "QueueReference={QueueId=$Q,Channel=CHAT},Priority=1,Delay=0" || stop "couldn't add rtdi-test-queue to rtdi-test-routing."
    say Added "rtdi-test-queue for chat to rtdi-test-routing"
  fi

  # 3. The security profile: Access Contact Control Panel and Custom views for the guide, and Connect assistant - View,
  #    Views - View and ContactFlowModules.Execute (run flow modules as tools; the admin website grants it when you tick a
  #    module under Flow modules) for the agent assist test. An existing one is reused as it is.
  profile rtdi-test-agent; P=$FID
  if [ "$P" != None ]; then say Reused "security profile rtdi-test-agent"
  else
    P=$(c create-security-profile --instance-id "$ID" --security-profile-name rtdi-test-agent \
      --description "Test agent for real-time data integration" \
      --permissions BasicAgentAccess CustomViews.Access Wisdom.View Views.View ContactFlowModules.Execute \
      --tags "$TAG=true" --query SecurityProfileId --output text) || stop "couldn't create the security profile rtdi-test-agent."
    say Created "security profile rtdi-test-agent"
  fi

  # 4. The test agent, with only the test routing profile and the test security profile.
  if [ "$U" != None ]; then
    c update-user-routing-profile --instance-id "$ID" --user-id "$U" --routing-profile-id "$RP" &&
      c update-user-security-profiles --instance-id "$ID" --user-id "$U" --security-profile-ids "$P" \
      || stop "couldn't update the user $USERNAME."
    say Reused "user $USERNAME"
  else
    # The password goes to the AWS CLI in a temporary file that only you can read, which the script deletes, so it never
    # appears in the process list.
    PWJ=${PW//\\/\\\\}; PWJ=${PWJ//\"/\\\"}
    INPUT="{}"; [ -z "$PW" ] || INPUT="{\"Password\":\"$PWJ\"}"
    PWF=$(umask 077; mktemp) || stop "couldn't create a temporary file for the password."
    trap 'rm -f "$PWF"' EXIT
    printf '%s' "$INPUT" > "$PWF"
    U="" UARN=""
    read -r U UARN < <(c create-user --instance-id "$ID" --username "$USERNAME" --cli-input-json "file://$PWF" \
      --identity-info FirstName=Test,LastName=Agent --phone-config PhoneType=SOFT_PHONE,AfterContactWorkTimeLimit=0 \
      --security-profile-ids "$P" --routing-profile-id "$RP" --tags "$TAG=true" --query '[UserId,UserArn]' --output text)
    rm -f "$PWF"; trap - EXIT
    PW="" PWJ="" INPUT=""
    [ -n "$U" ] || stop "couldn't create the user $USERNAME."
    say Created "user $USERNAME"
  fi

  # 5. The workspace: the Modern layout, visible only to the users it is assigned to, assigned to the test agent.
  workspace rtdi-modern; W=$FID
  if [ "$W" != None ]; then say Reused "workspace rtdi-modern"
  else
    W=$(c create-workspace --instance-id "$ID" --name rtdi-modern --description "Modern layout for the real-time data integration test agent" \
      --tags "$TAG=true" --query WorkspaceId --output text) || stop "couldn't create the workspace rtdi-modern."
    say Created "workspace rtdi-modern"
  fi
  PAGE=$(c list-workspace-pages --instance-id "$ID" --workspace-id "$W" --query "WorkspacePageList[?Page=='connect:AGENT'].ResourceArn" --output text) \
    || stop "couldn't read the pages of rtdi-modern in $ALIAS; see the error above."
  PAGE_OK=yes
  if [ -z "$(echo "$PAGE" | first)" ]; then
    if c create-workspace-page --instance-id "$ID" --workspace-id "$W" --page connect:AGENT \
      --resource-arn "arn:$PARTITION:connect:$REGION:aws:view/agent-workspace-modern:1" >/dev/null; then
      say Added "the Agent Workspace - Modern page to rtdi-modern"
    else
      PAGE_OK=no
      echo "Couldn't add the page; see the error above."
    fi
  fi
  c update-workspace-visibility --instance-id "$ID" --workspace-id "$W" --visibility ASSIGNED || stop "couldn't set rtdi-modern to assigned users only."
  c associate-workspace --instance-id "$ID" --workspace-id "$W" --resource-arns "$UARN" >/dev/null \
    || stop "couldn't assign rtdi-modern to $USERNAME."
  say Assigned "rtdi-modern to $USERNAME only"

  URL=$(c describe-instance --instance-id "$ID" --query Instance.InstanceAccessUrl --output text)
  if [ "$PAGE_OK" = yes ]; then
    echo "DONE: the test agent is ready."
  else
    echo "NOT DONE: add the Modern layout in the admin website. Choose UI Management, Workspaces and rtdi-modern. In Pages, choose"
    echo "  Add page and Use existing Connect page, then Agent Workspace, Agent Workspace - Modern and view version 1, and Save."
  fi
  echo "Test queue ARN (Test queue ARN field in Step 3): $QARN"
  echo "Agent workspace for the test agent: ${URL%/}/agent/  (sign in as $USERNAME)"
  [ "$IDM" = CONNECT_MANAGED ] || echo "This instance signs users in through $IDM: sign in as $USERNAME through it."
)
```

The test agent sees the Modern layout the next time they open the agent workspace. See [Assign an agent workspace layout to agents](https://docs.aws.amazon.com/connect/latest/adminguide/assign-agent-workspace-layout.html). If your instance signs users in through SAML, Connect Customer users have no password, so the user must also exist in your identity provider before you can sign in as it.

**Note**  
The agent workspace also shows the Connect Customer Customer Profiles, Cases and Connect assistant apps to agents whose security profile allows them. These apps hold Connect Customer records, not Salesforce records, and the guide never reads or writes them; see [Customer Profiles](customer-profiles.md) and [Cases](cases.md). On an instance where an app isn't set up, an agent who has its permission, such as a test agent with the **Admin** security profile's permissions, sees a message such as **The Cases feature hasn't been set up**.  
To hide an app your agents don't use, in the Connect Customer admin website choose **Users**, **Security profiles** and the agents' security profile, clear **Customer profiles - View**, **Cases - View** or **Connect assistant - View**, and choose **Save**. Keep **Connect assistant - View** to use the Connect assistant with the guide; see [Use the Connect assistant with real-time data integration](real-time-data-integration-ai-agents.md) and [List of security profile permissions](https://docs.aws.amazon.com/connect/latest/adminguide/security-profile-list.html).

## Give your security profile the permissions to edit the guide's flows
<a name="real-time-data-integration-instance-guides"></a>

Step-by-step guides need security profile permissions for whoever edits and publishes the guide's flows, as well as the test agent's. See [Enable step-by-step guides](enable-guided-experiences-sg.md). Check that your security profile has each of these permissions, including **Views - View**, which the **Admin** security profile doesn't always have.

**To give your security profile the permissions**
+ In the Connect Customer admin website, choose **Users**, **Security profiles**, and your own security profile. In **Channels and flows**, select **View** for **Views**, and **Create**, **Edit** and **Publish** for **Flows**. Choose **Save**.

Every step-by-step guide runs as a chat contact, so the guide counts toward the instance's concurrent active chats quota. For the quota, see [Connect Customer service quotas](amazon-connect-service-limits.md). Check it before you go live; see [Plan for scale](real-time-data-integration-limits.md).