Amazon-Connect-CopyでAmazon Connectインスタンスのコピーをしてみた – Amazon Connect アドベントカレンダー 2022

Amazon Connectインスタンスの複製やバックアップ・リストアが簡単にできます
2022.12.09

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは、中川です。

Amazon Connect アドベントカレンダー 2022、9日目の記事です!
Amazon Connect アドベントカレンダー 2022はクラスメソッドとギークフィードさんの有志が募ってチャレンジしている企画になります。

本日時点ではAmazon Connectの標準としてコピーやバックアップの機能はサポートされておりません。
一部のコンポーネントはCloudFormationに対応しております *1 が、すべてのコンポーネントは対応されていないため全てをIaCで管理することもできないです。
そのためAamzon Connectの設定をバックアップや同じ設定の他の環境にコピー(非本番から本番)したいようなケースでは、手作業や事前にスクリプトの作り込み必要でした。

Amazon-Connect-Copy は、Amazon ConnectインスタンスのコンポーネントをまるっとコピーできるBashスクリプトで、aws-samples で公開されています。
Amazon Connectインスタンスの複製やバックアップなど数時間かかっていたような作業を数分に減らし、また作り込み不要で簡単に利用できます。
本ブログではAmazon-Connect-Copyを試してみましたので、ご紹介します。

対象コンポーネント

コピー対象のコンポーネントは以下になります。

サポートされているコンポーネント

  • Lambda (事前にデプロイが必要)
  • Lex (事前にデプロイが必要)
  • プロンプト(事前アップロードが必要)
  • オペレーション時間
  • キュー
  • ルーティングプロファイル
  • コンタクトフロー
  • コンタクトフローモジュール

サポートされていないコンポーネント

  • ユーザー
  • セキュリティプロファイル
  • 電話番号
  • クイック接続
  • 既存のキュー
  • ヒストリカルメトリクス、レポート
  • CTR
  • カスタム語彙
  • Contact Lensルール

やってみた

ソースとなるインスタンス(copy-source)をコピーして、ターゲットのインスタンス(copy-target)に複製する流れを行います。

対象とするAmazon Connectのコンポーネントは以下とします。

  • Lambda
  • プロンプト
  • オペレーション時間
  • キュー
  • コンタクトフロー

前提

以下の前提のもと実行しています。

  • 実行環境で以下がインストールされていること
    • AWS CLI (動作確認されているバージョン2.8.6。本ブログでは2.9.5を使用)
    • jq
  • aws-samples/amazon-connect-copy はクローンされて bin/* のパスを通していること

準備

リストアの準備として以下を事前に行います。

  • 複製のターゲットとなるAmazon Connectインスタンス(copy-target)を作成
  • コンタクトフローで使用されるLambda関数(connect-copy-function)をターゲットのインスタンスに追加
  • コンタクトフローで使用されるプロンプト(sample_sound.wav)をターゲットのインスタンスにアップロード

動作確認用に以下のコールフロー、キュー、オペレーション時間を用意しました。

コンタクトフロー(test-flow)

キュー(test-queue)、オペレーション時間(test-operation)

ソースインスタンスを保存

準備ができましたので、ソースインスタンスのコンポートを保存します。保存はconnect_save コマンドを使用します。

$ connect_save copy-source

実行すると以下のようにコピーされたコンポーネントが出力されます。

Instance Alias: copy-source (in directory "copy-source")
AWS Profile: (default)
Contact Flow Prefix:
Instance ID: 307e58be-45b2-4ca6-829a-a987fde0b515

8 prompts listed in "copy-source/prompts.json"

2 hours of operations listed in "copy-source/hours.json"
Exporting hours of operation Basic Hours
Exporting hours of operation test-operation

2 queues listed in "copy-source/queues.json"
Exporting queue BasicQueue
Exporting queue test-queue

1 routing profiles listed in "copy-source/routings.json"
Exporting routing profile Basic Routing Profile

0 contact flow modules listed in "copy-source/modules.json"

20 contact flows listed in "copy-source/flows.json"
Exporting contact flow Default agent hold
Exporting contact flow Default agent transfer
Exporting contact flow Default agent whisper
Exporting contact flow Default customer hold
Exporting contact flow Default customer queue
Exporting contact flow Default customer whisper
Exporting contact flow Default outbound
Exporting contact flow Default queue transfer
Exporting contact flow Sample AB test
Exporting contact flow Sample Lambda integration
Exporting contact flow Sample disconnect flow
Exporting contact flow Sample inbound flow (first contact experience)
Exporting contact flow Sample interruptible queue flow with callback
Exporting contact flow Sample note for screenpop
Exporting contact flow Sample queue configurations flow
Exporting contact flow Sample queue customer
Exporting contact flow Sample recording behavior
Exporting contact flow Sample secure input with agent
Exporting contact flow Sample secure input with no agent
Exporting contact flow test-flow

All done

ディレクトリを確認すると、各コンポーネントごとにファイルが出力されていました。

$ tree
.
├── copy-source
│   ├── flow_Default%20agent%20hold.json
│   ├── flow_Default%20agent%20transfer.json
│   ├── flow_Default%20agent%20whisper.json
│   ├── flow_Default%20customer%20hold.json
│   ├── flow_Default%20customer%20queue.json
│   ├── flow_Default%20customer%20whisper.json
│   ├── flow_Default%20outbound.json
│   ├── flow_Default%20queue%20transfer.json
│   ├── flow_Sample%20AB%20test.json
│   ├── flow_Sample%20Lambda%20integration.json
│   ├── flow_Sample%20disconnect%20flow.json
│   ├── flow_Sample%20inbound%20flow%20%28first%20contact%20experience%29.json
│   ├── flow_Sample%20interruptible%20queue%20flow%20with%20callback.json
│   ├── flow_Sample%20note%20for%20screenpop.json
│   ├── flow_Sample%20queue%20configurations%20flow.json
│   ├── flow_Sample%20queue%20customer.json
│   ├── flow_Sample%20recording%20behavior.json
│   ├── flow_Sample%20secure%20input%20with%20agent.json
│   ├── flow_Sample%20secure%20input%20with%20no%20agent.json
│   ├── flow_test-flow.json
│   ├── flows.json
│   ├── hour_Basic%20Hours.json
│   ├── hour_test-operation.json
│   ├── hours.json
│   ├── instance.json
│   ├── instance.var
│   ├── modules.json
│   ├── prompts.json
│   ├── queue_BasicQueue.json
│   ├── queue_test-queue.json
│   ├── queues.json
│   ├── routingQs_Basic%20Routing%20Profile.json
│   ├── routing_Basic%20Routing%20Profile.json
│   └── routings.json
└── copy-source.log

保存はこれだけで完了です。

ターゲットインスタンスにコピー

次に保存したコンポーネントをターゲットにコピーをしていきます。
ソースインスタンスとターゲットインスタンスの設定を比較をするため、ターゲットインスタンスでも同じようにconnect_saveコマンドを実行します。

$ connect_save copy-target

ターゲットで作成・更新したくないコンポーネントがあれば、ヘルパーファイルを利用できます。 ヘルパーファイルは connect_diff helper コマンドを実行して作成されます。

$ connect_diff copy-source copy-target helper

実行するとhelperディレクトリが作成され、コンポーネントの比較や変数が定義されたファイルが作成されます。

$ tree helper/
helper/
├── flow_template.json
├── helper.new
├── helper.old
├── helper.sed
├── helper.var
└── module_template.json
  • helper.new:新規作成するコンポーネント(ソースにあって、ターゲットにないもの)
  • helper.old:更新するコンポーネント(ソースとターゲットにあるもの)
  • helper.sed:参照を修正するSED スクリプト
  • helper.var:2インスタンスの変数(インスタンス名やLambdaプレフィックスなど)

helper.new を開くと、以下のように新規作成するコンポーネントが書かれています。もし、この中にターゲットに作成したくないコンポーネントがあれば直接ファイルを修正します。

hour_test-operation.json
queue_test-queue.json
flow_test-flow.json

以上でコピーの準備ができました。

コピーはconnect_copy helper コマンドを実行します。-d オプションを付けて実行するとドライランできるので、まずドライランから実行します。

$ connect_copy -d helper
Dry Run
Instance Alias A: copy-source (in directory "copy-source")
Instance Alias B: copy-target (in directory "copy-target")
Helper Directory: helper
AWS Profile B in use: (default)
Context Flow Prefix:

Prompts
-------
All prompts in the source instance exist in the target instance.

Hours of operations
-------------------

Creating 1 Hours of operations
1. hour_test-operation.json
Dry-create hours of operation
{
  "Name": "test-operation",
  "Description": "test-operation",
  "TimeZone": "Japan",
  "Config": [
    {
      "Day": "WEDNESDAY",
      "StartTime": {
        "Hours": 9,
        "Minutes": 0
      },
      "EndTime": {
        "Hours": 17,
        "Minutes": 0
      }
    },
    {
      "Day": "FRIDAY",
      "StartTime": {
        "Hours": 9,
        "Minutes": 0
      },
      "EndTime": {
        "Hours": 17,
        "Minutes": 0
      }
    },
    {
      "Day": "TUESDAY",
      "StartTime": {
        "Hours": 9,
        "Minutes": 0
      },
      "EndTime": {
        "Hours": 17,
        "Minutes": 0
      }
    },
    {
      "Day": "SUNDAY",
      "StartTime": {
        "Hours": 9,
        "Minutes": 0
      },
      "EndTime": {
        "Hours": 17,
        "Minutes": 0
      }
    },
    {
      "Day": "SATURDAY",
      "StartTime": {
        "Hours": 9,
        "Minutes": 0
      },
      "EndTime": {
        "Hours": 17,
        "Minutes": 0
      }
    },
    {
      "Day": "THURSDAY",
      "StartTime": {
        "Hours": 9,
        "Minutes": 0
      },
      "EndTime": {
        "Hours": 17,
        "Minutes": 0
      }
    },
    {
      "Day": "MONDAY",
      "StartTime": {
        "Hours": 9,
        "Minutes": 0
      },
      "EndTime": {
        "Hours": 17,
        "Minutes": 0
      }
    }
  ],
  "Tags": {},
  "InstanceId": "5b0d02cb-b32b-4f84-900d-e77e9938f552"
}


Checking 1 hours of operations for an update
1. hour_Basic%20Hours.json ... same

Queues
------

Creating 1 queues
1. queue_test-queue.json
Dry-create queue
{
  "Name": "test-queue",
  "Description": "test",
  "HoursOfOperationId": "b364d55f-5cd7-471b-88e1-5b9042dd4c61",
  "Tags": {},
  "InstanceId": "5b0d02cb-b32b-4f84-900d-e77e9938f552"
}


Checking 1 queues for an update
1. queue_BasicQueue.json ... same

Routing Profiles
----------------
No routing profiles to create
No routing profiles to update

Contact Flow Modules Creation
-----------------------------
No contact flow modules to create

Contact Flows Creation
----------------------

Creating 1 contact flows
1. flow_test-flow.json
Dry-create contact flow from Template (Default flows)
--instance-id 5b0d02cb-b32b-4f84-900d-e77e9938f552
--name "test-flow"
--type CONTACT_FLOW


Contact Flow Modules Update
---------------------------
No contact flow modules to update

Contact Flows Update
--------------------

Checking 19 contact flows for an update
1. flow_Default%20agent%20hold.json ... same
2. flow_Default%20agent%20transfer.json ... same
3. flow_Default%20agent%20whisper.json ... same
4. flow_Default%20customer%20hold.json ... same
5. flow_Default%20customer%20queue.json ... same
6. flow_Default%20customer%20whisper.json ... same
7. flow_Default%20outbound.json ... same
8. flow_Default%20queue%20transfer.json ... same
9. flow_Sample%20AB%20test.json ... same
10. flow_Sample%20Lambda%20integration.json ... same
11. flow_Sample%20disconnect%20flow.json ... same
12. flow_Sample%20inbound%20flow%20%28first%20contact%20experience%29.json ... same
13. flow_Sample%20interruptible%20queue%20flow%20with%20callback.json ... same
14. flow_Sample%20note%20for%20screenpop.json ... same
15. flow_Sample%20queue%20configurations%20flow.json ... same
16. flow_Sample%20queue%20customer.json ... same
17. flow_Sample%20recording%20behavior.json ... same
18. flow_Sample%20secure%20input%20with%20agent.json ... same
19. flow_Sample%20secure%20input%20with%20no%20agent.json ... same

3 actions on the target instance

The AWS CLI commands carrying out such actions can be found in: helper.log

No actions were carried out in Dry-run mode

ドライランの実行内容を確認して問題なければ、コピーを実行します。

$ connect_copy helper
Instance Alias A: copy-source (in directory "copy-source")
Instance Alias B: copy-target (in directory "copy-target")
Helper Directory: helper
AWS Profile B in use: (default)
Context Flow Prefix:

Prompts
-------
All prompts in the source instance exist in the target instance.

Hours of operations
-------------------

Creating 1 Hours of operations
1. hour_test-operation.json

Checking 1 hours of operations for an update
1. hour_Basic%20Hours.json ... same

Queues
------

Creating 1 queues
1. queue_test-queue.json

Checking 1 queues for an update
1. queue_BasicQueue.json ... same

Routing Profiles
----------------
No routing profiles to create
No routing profiles to update

Contact Flow Modules Creation
-----------------------------
No contact flow modules to create

Contact Flows Creation
----------------------

Creating 1 contact flows
1. flow_test-flow.json

Contact Flow Modules Update
---------------------------
No contact flow modules to update

Contact Flows Update
--------------------

Checking 20 contact flows for an update
1. flow_Default%20agent%20hold.json ... same
2. flow_Default%20agent%20transfer.json ... same
3. flow_Default%20agent%20whisper.json ... same
4. flow_Default%20customer%20hold.json ... same
5. flow_Default%20customer%20queue.json ... same
6. flow_Default%20customer%20whisper.json ... same
7. flow_Default%20outbound.json ... same
8. flow_Default%20queue%20transfer.json ... same
9. flow_Sample%20AB%20test.json ... same
10. flow_Sample%20Lambda%20integration.json ... same
11. flow_Sample%20disconnect%20flow.json ... same
12. flow_Sample%20inbound%20flow%20%28first%20contact%20experience%29.json ... same
13. flow_Sample%20interruptible%20queue%20flow%20with%20callback.json ... same
14. flow_Sample%20note%20for%20screenpop.json ... same
15. flow_Sample%20queue%20configurations%20flow.json ... same
16. flow_Sample%20queue%20customer.json ... same
17. flow_Sample%20recording%20behavior.json ... same
18. flow_Sample%20secure%20input%20with%20agent.json ... same
19. flow_Sample%20secure%20input%20with%20no%20agent.json ... same
20. flow_test-flow.json ... changed

Associating Lambda functions to copy-target
1. arn:aws:lambda:ap-northeast-1:12345678XXXX:function:connect-copy-function ... already associated

4 actions on the target instance

The AWS CLI commands carrying out such actions can be found in: helper.log

All done

ターゲットインスタンスに接続すると、期待通りフローやオペレーション時間が作成され、正常にコピーできていることを確認できました!

さいごに

Amazon Connectインスタンスのコピーをできる Amazon-Connect-Copy を試してみました。
簡単にインスタンスのコピーができますので、環境の複製やバックアップ・リストアをしたいときに便利なツールです。すべてのコンポーネントをコピーはできませんので、利用状況に応じて追加でスクリプトの用意や操作を合わせて検討したいです。

脚注

  1. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/AWS_Connect.html