AWS CloudFormationで、コンタクト終了後にAmazon Connectパフォーマンス評価を自動で行うルールを作成してみた

AWS CloudFormationで、コンタクト終了後にAmazon Connectパフォーマンス評価を自動で行うルールを作成してみた

2025.10.10

はじめに

以前、コンタクト終了後にAmazon Connectパフォーマンス評価を自動で行うルールの作成方法をご紹介しました。

https://dev.classmethod.jp/articles/amazon-connect-performance-evaluation-auto-evaluation/

今回は、AWS CloudFormationを使用して、コンタクト終了後にAmazon Connectパフォーマンス評価を自動で行うルールを作成してみます。作成するルールの内容は、上記のブログとほぼ同じですが、カテゴリ名などの名前は異なります。

なお、AWSサポートにフィードバック済みですが、執筆時点では一部正常に動作しない点があります。

評価フォームもCloudFormationで作成可能ですが、現時点では以下の制限があることに注意が必要です。

  • 生成AIによる自動化オプションの設定はCloudFormationでサポートされていない
  • 「評価の自動提出を有効化」の設定が動作しない

詳細は、以下の記事をご参照ください。

https://dev.classmethod.jp/articles/amazon-connect-evaluation-form-cloudformation/

前提条件

評価フォームは作成済みであることを前提とします。

また、その評価フォームで「評価の自動提出を有効化」の設定が有効化されている必要があります。
cm-hirai-screenshot 2025-10-01 13.57.02

スタックの作成

評価フォームのARNを確認

AWS CloudShellで評価フォームのARN(EvaluationFormArn)を確認します。

			
			$ aws connect list-evaluation-forms \
    --instance-id 3ff2093d-af96-43fd-b038-3c07cdd7609c \
    --region ap-northeast-1
{
    "EvaluationFormSummaryList": [
        {
            "EvaluationFormId": "78d88714-7b2c-4f25-8d55-4638a5ece4c0",
            "EvaluationFormArn": "arn:aws:connect:ap-northeast-1:111111111111:instance/3ff2093d-af96-43fd-b038-3c07cdd7609c/evaluation-form/78d88714-7b2c-4f25-8d55-4638a5ece4c0",
            "Title": "カスタマーサービス評価フォーム",
            "CreatedTime": "2025-09-04T02:22:35.069000+00:00",
            "CreatedBy": "arn:aws:sts::111111111111:assumed-role/cm-hirai.yuji-Read/cm-hirai.yuji",
            "LastModifiedTime": "2025-09-08T23:55:45.020000+00:00",
            "LastModifiedBy": "arn:aws:connect:ap-northeast-1:111111111111:instance/3ff2093d-af96-43fd-b038-3c07cdd7609c/agent/104b4727-a2ef-4f12-8daf-6068ce627667",
            "LastActivatedTime": "2025-09-08T23:55:45.020000+00:00",
            "LastActivatedBy": "hirai",
            "LatestVersion": 2,
            "ActiveVersion": 2
        },

		

CloudFormationテンプレートを利用してスタックを作成

以下のCloudFormationテンプレートを利用し、スタックを作成します。

			
			AWSTemplateFormatVersion: '2010-09-09'
Description: 'CloudFormation template for Amazon Connect Contact Lens auto-evaluation rules'

Parameters:
  ConnectInstanceArn:
    Type: String
    Description: ARN of the Amazon Connect instance
    AllowedPattern: '^arn:aws[-a-z0-9]*:connect:[-a-z0-9]*:[0-9]{12}:instance/[-a-zA-Z0-9]*$'

  EvaluationFormArn:
    Type: String
    Description: ARN of the evaluation form for auto-evaluation
    AllowedPattern: '^arn:aws[-a-z0-9]*:connect:[-a-z0-9]*:[0-9]{12}:instance/[-a-zA-Z0-9]*/evaluation-form/[-a-zA-Z0-9]*$'

  RuleName:
    Type: String
    Description: Name of the rule
    Default: 'AutoEvaluationRule'
    AllowedPattern: '^[a-zA-Z0-9._-]{1,200}$'

  ContactCategoryName:
    Type: String
    Description: Contact category name for rule identification
    Default: 'AutoEvaluationTriggered'
    MaxLength: 200

  MinAgentInteractionSeconds:
    Type: Number
    Description: Minimum agent interaction duration in seconds
    Default: 1
    MinValue: 1

  PublishStatus:
    Type: String
    Description: Publish status of the rule
    Default: 'PUBLISHED'
    AllowedValues: ['DRAFT', 'PUBLISHED']

Resources:
  # 通話後分析が利用可能になったときに自動評価を実行するルール
  PostCallAutoEvaluationRule:
    Type: AWS::Connect::Rule
    Properties:
      Name: !Sub '${RuleName}-PostCall'
      InstanceArn: !Ref ConnectInstanceArn
      PublishStatus: !Ref PublishStatus
      TriggerEventSource:
        EventSourceName: 'OnPostCallAnalysisAvailable'
      Function: !Sub |
        {
          "Version": "2022-11-25",
          "RuleFunction": {
            "Operator": "AND",
            "Operands": [
              {
                "Operator": "NumberGreaterOrEqualTo",
                "Operands": [${MinAgentInteractionSeconds}],
                "ComparisonValue": "$.ContactLens.PostCall.Agent.AgentInteractionDurationSecs",
                "Negate": false
              }
            ]
          }
        }
      Actions:
        AssignContactCategoryActions:
          - {}
        SubmitAutoEvaluationActions:
          - EvaluationFormArn: !Ref EvaluationFormArn
      Tags:
        - Key: 'Purpose'
          Value: 'AutoEvaluation'
        - Key: 'CreatedBy'
          Value: 'CloudFormation'

  # チャット後分析が利用可能になったときに自動評価を実行するルール
  PostChatAutoEvaluationRule:
    Type: AWS::Connect::Rule
    Properties:
      Name: !Sub '${RuleName}-PostChat'
      InstanceArn: !Ref ConnectInstanceArn
      PublishStatus: !Ref PublishStatus
      TriggerEventSource:
        EventSourceName: 'OnPostChatAnalysisAvailable'
      Function: !Sub |
        {
          "Version": "2022-11-25",
          "RuleFunction": {
            "Operator": "AND",
            "Operands": [
              {
                "Operator": "NumberGreaterOrEqualTo",
                "Operands": [${MinAgentInteractionSeconds}],
                "ComparisonValue": "$.ContactLens.PostChat.Agent.AgentInteractionDurationSecs",
                "Negate": false
              }
            ]
          }
        }
      Actions:
        AssignContactCategoryActions:
          - {}
        SubmitAutoEvaluationActions:
          - EvaluationFormArn: !Ref EvaluationFormArn
      Tags:
        - Key: 'Purpose'
          Value: 'AutoEvaluation'
        - Key: 'CreatedBy'
          Value: 'CloudFormation'

Outputs:
  PostCallRuleArn:
    Description: 'ARN of the post-call auto-evaluation rule'
    Value: !Ref PostCallAutoEvaluationRule.RuleArn
    Export:
      Name: !Sub '${AWS::StackName}-PostCallRuleArn'

  PostChatRuleArn:
    Description: 'ARN of the post-chat auto-evaluation rule'
    Value: !Ref PostChatAutoEvaluationRule.RuleArn
    Export:
      Name: !Sub '${AWS::StackName}-PostChatRuleArn'

		

スタック作成時のパラメータは以下のとおりです。
cm-hirai-screenshot 2025-10-01 13.50.46

ContactCategoryNameとは、カテゴリ名のことで、ルールが発火したコンタクトにはこのカテゴリ名が付与されます。

cm-hirai-screenshot 2025-10-01 16.19.10

作成されたルールの確認

スタック作成完了後、作成されたルールを確認してみます。
cm-hirai-screenshot 2025-10-01 13.53.33
以下のエラーが表示されます。

フォームは存在しません。削除されたか非アクティブになっています。

cm-hirai-screenshot 2025-10-01 13.54.26

執筆時点では、CloudFormationで作成したルールに評価フォームが正常に設定されません。

そのため、手動で自動評価させたい評価フォームを選択します。

なお、「評価の自動提出を有効化」の設定が有効化されている評価フォームのみが選択肢に表示されます。

cm-hirai-screenshot 2025-10-01 13.54.55

保存後、通話対応を行うと、評価フォームが自動実行されることを確認できます。

cm-hirai-screenshot 2025-10-01 16.19.10のコピー

自動評価が無効化されている場合

評価フォームでは、自動評価が有効化されている必要があります。自動評価が無効化されている評価フォームを指定してスタックを作成しようとすると、以下のエラーが発生します。

Resource handler returned message: "Argos Evaluation Definition Form ID: 74c6f383-7f49-4de1-90cd-287c4b2584c0 in instance: 3ff2093d-af96-43fd-b038-3c07cdd7609c does not have AutoEvaluation enabled (Service: Connect, Status Code: 400, Request ID: e79f00a8-22a8-4012-b9d5-7ea2bb38ca47) (SDK Attempt Count: 1)" (RequestToken: 8c13d9aa-a2cc-7311-cd16-d24b0e5c315b, HandlerErrorCode: InvalidRequest)

cm-hirai-screenshot 2025-10-01 16.12.58

最後に

AWS CloudFormationを使用して、Amazon Connectパフォーマンス評価の自動評価ルールを作成しました。

執筆時点では、評価フォームが正常に設定されず、手動での設定が必要となります。今後の改善に期待したいと思います。

参考

https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-connect-rule-submitautoevaluationaction.html

この記事をシェアする

FacebookHatena blogX

関連記事