AWS Entity Resolutionの高度なリアルタイムマッチングをCLIで試してみた
はじめに
AWS Entity Resolutionは、複数のデータストア間で関連するレコードの照合や重複レコードの特定を行うフルマネージドサービスです。
2026年7月22日、AWS Entity Resolutionで高度なルールベースマッチング(AND/OR条件)がリアルタイムマッチングに対応しました。
単純ルール(ruleBasedProperties)と高度なルール(ruleConditionProperties)の違いは以下のとおりです。
| 項目 | 単純ルール | 高度なルール |
|---|---|---|
| パラメータ | ruleBasedProperties |
ruleConditionProperties |
| 条件指定 | マッチキーの組み合わせのみ | Exact/Fuzzy関数とAND/OR/括弧を組み合わせた条件式 |
| リアルタイムマッチング | 対応済み | 今回新規対応 |
| StartMatchingJob | 利用可能 | 本検証ではInternalServerException |
| GenerateMatchId実行前の初回バッチ | 必要 | 本検証では不要(GenerateMatchIdが即動作) |
AWS Entity Resolutionの基本的な使い方は以下を参照してください。
本記事では、ruleConditionPropertiesでAND/OR条件のワークフローを作成し、GenerateMatchId APIでリアルタイムにレコード照合が動作することを確認します。リアルタイムマッチングの詳細は公式ドキュメントを参照してください。
検証内容
検証環境
| 項目 | 値 |
|---|---|
| リージョン | ap-northeast-1 |
| AWS CLI | 2.27.31 |
| データ件数 | 5件 |
| リソース | 名前 |
|---|---|
| S3 バケット | entity-resolution-advanced-realtime-demo-20260723 |
| Glue データベース | entity_resolution_demo |
| Glue テーブル | customers(unique_id, name, email, phone) |
| IAM ロール | EntityResolutionAdvancedRealtimeDemo |
| スキーママッピング | advanced-realtime-demo-schema(Email, Phone をマッチキー) |
| ワークフロー(AND) | advanced-realtime-demo(Exact(Email) AND Exact(Phone)) |
| ワークフロー(OR) | advanced-realtime-demo-or(Exact(Email) OR Exact(Phone)) |
前提リソースの作成
検証用の顧客データをCSVで用意し、S3バケットへ配置しました。
cat > customers.csv <<'EOF'
unique_id,name,email,phone
c001,Taro Yamada,taro@example.com,+81-90-1234-5678
c002,Hanako Sato,hanako@example.com,+81-80-9876-5432
c003,Jiro Suzuki,jiro@example.com,+81-70-1111-2222
c004,Keiko Tanaka,keiko@example.com,+81-70-3333-4444
c005,Taro Yamada,taro@example.com,+81-90-1234-5678
EOF
aws s3api create-bucket \
--bucket entity-resolution-advanced-realtime-demo-20260723 \
--create-bucket-configuration LocationConstraint=ap-northeast-1 \
--region ap-northeast-1
aws s3 cp customers.csv \
s3://entity-resolution-advanced-realtime-demo-20260723/input/customers.csv \
--region ap-northeast-1
Glueデータベースと、S3上のCSVを参照する外部テーブルを作成しました。
aws glue create-database \
--database-input '{
"Name": "entity_resolution_demo"
}' \
--region ap-northeast-1
aws glue create-table \
--database-name entity_resolution_demo \
--table-input '{
"Name": "customers",
"TableType": "EXTERNAL_TABLE",
"Parameters": {
"classification": "csv",
"skip.header.line.count": "1"
},
"StorageDescriptor": {
"Columns": [
{"Name": "unique_id", "Type": "string"},
{"Name": "name", "Type": "string"},
{"Name": "email", "Type": "string"},
{"Name": "phone", "Type": "string"}
],
"Location": "s3://entity-resolution-advanced-realtime-demo-20260723/input/",
"InputFormat": "org.apache.hadoop.mapred.TextInputFormat",
"OutputFormat": "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat",
"SerdeInfo": {
"SerializationLibrary": "org.apache.hadoop.hive.serde2.OpenCSVSerde"
}
}
}' \
--region ap-northeast-1
Entity ResolutionがGlueとS3を参照するためのIAMロールを作成しました。
cat > trust-policy.json <<'EOF'
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {
"Service": "entityresolution.amazonaws.com"
},
"Action": "sts:AssumeRole"
}]
}
EOF
aws iam create-role \
--role-name EntityResolutionAdvancedRealtimeDemo \
--assume-role-policy-document file://trust-policy.json
cat > permissions-policy.json <<'EOF'
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"glue:GetDatabase",
"glue:GetTable",
"glue:GetTables",
"glue:GetPartitions"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::entity-resolution-advanced-realtime-demo-20260723",
"arn:aws:s3:::entity-resolution-advanced-realtime-demo-20260723/*"
]
}
]
}
EOF
aws iam put-role-policy \
--role-name EntityResolutionAdvancedRealtimeDemo \
--policy-name EntityResolutionAccess \
--policy-document file://permissions-policy.json
スキーママッピングを作成しました。emailとphoneをそれぞれEmail、Phoneのマッチキーとして定義しています。
aws entityresolution create-schema-mapping \
--schema-name advanced-realtime-demo-schema \
--mapped-input-fields '[
{
"fieldName": "unique_id",
"type": "UNIQUE_ID"
},
{
"fieldName": "name",
"type": "NAME"
},
{
"fieldName": "email",
"type": "EMAIL_ADDRESS",
"matchKey": "Email"
},
{
"fieldName": "phone",
"type": "PHONE",
"matchKey": "Phone"
}
]' \
--output-attributes '[
"unique_id",
"name",
"email",
"phone"
]' \
--region ap-northeast-1
高度なルールベースワークフローの作成
ruleConditionPropertiesにAND条件(Exact(Email) AND Exact(Phone))を指定し、リアルタイムマッチングを有効にしてワークフローを作成します。
aws entityresolution create-matching-workflow \
--workflow-name advanced-realtime-demo \
--input-source-config '[{
"inputSourceARN": "arn:aws:glue:ap-northeast-1:123456789012:table/entity_resolution_demo/customers",
"schemaName": "advanced-realtime-demo-schema"
}]' \
--output-source-config '[{
"outputS3Path": "s3://entity-resolution-advanced-realtime-demo-20260723/output/",
"output": [
{"name": "unique_id", "hashed": false},
{"name": "name", "hashed": false},
{"name": "email", "hashed": false},
{"name": "phone", "hashed": false}
]
}]' \
--resolution-techniques '{
"resolutionType": "RULE_MATCHING",
"enableRealTimeMatching": true,
"ruleConditionProperties": {
"rules": [{
"ruleName": "email-and-phone",
"condition": "Exact(Email) AND Exact(Phone)"
}]
}
}' \
--role-arn arn:aws:iam::123456789012:role/EntityResolutionAdvancedRealtimeDemo \
--region ap-northeast-1
レスポンスのresolutionTechniquesにruleConditionPropertiesとenableRealTimeMatching: trueが含まれています。
ワークフロー作成レスポンス全文
{
"workflowName": "advanced-realtime-demo",
"workflowArn": "arn:aws:entityresolution:ap-northeast-1:123456789012:matchingworkflow/advanced-realtime-demo",
"inputSourceConfig": [
{
"inputSourceARN": "arn:aws:glue:ap-northeast-1:123456789012:table/entity_resolution_demo/customers",
"schemaName": "advanced-realtime-demo-schema"
}
],
"resolutionTechniques": {
"resolutionType": "RULE_MATCHING",
"ruleConditionProperties": {
"rules": [
{
"ruleName": "email-and-phone",
"condition": "Exact(Email) AND Exact(Phone)"
}
]
},
"enableRealTimeMatching": true
},
"roleArn": "arn:aws:iam::123456789012:role/EntityResolutionAdvancedRealtimeDemo"
}
GenerateMatchId によるリアルタイムマッチング
まず、c001を投入しました。
aws entityresolution generate-match-id \
--workflow-name advanced-realtime-demo \
--records '[{
"inputSourceARN": "arn:aws:glue:ap-northeast-1:123456789012:table/entity_resolution_demo/customers",
"uniqueId": "c001",
"recordAttributeMap": {
"email": "taro@example.com",
"phone": "+81-90-1234-5678"
}
}]' \
--region ap-northeast-1
新しいmatchIdが発行され、matchRuleはNoRuleでした。GenerateMatchIdで先行して投入されたレコードがなく、照合対象が存在しないためです。
{
"matchGroups": [
{
"records": [
{
"inputSourceARN": "arn:aws:glue:ap-northeast-1:123456789012:table/entity_resolution_demo/customers",
"recordId": "c001"
}
],
"matchId": "1e92cde4dec84674a93cd7d089f36a02",
"matchRule": "NoRule"
}
],
"failedRecords": []
}
次に、c001と同一のメールアドレスおよび電話番号を持つc005を投入しました。
aws entityresolution generate-match-id \
--workflow-name advanced-realtime-demo \
--records '[{
"inputSourceARN": "arn:aws:glue:ap-northeast-1:123456789012:table/entity_resolution_demo/customers",
"uniqueId": "c005",
"recordAttributeMap": {
"email": "taro@example.com",
"phone": "+81-90-1234-5678"
}
}]' \
--region ap-northeast-1
c001と同じmatchIdが返り、matchRuleは定義したルール名email-and-phoneになりました。メールアドレスと電話番号の両方が一致したため、AND条件でマッチしています。
{
"matchGroups": [
{
"records": [
{
"inputSourceARN": "arn:aws:glue:ap-northeast-1:123456789012:table/entity_resolution_demo/customers",
"recordId": "c005"
}
],
"matchId": "1e92cde4dec84674a93cd7d089f36a02",
"matchRule": "email-and-phone"
}
],
"failedRecords": []
}
最後に、メールアドレスと電話番号のどちらも異なるc002を投入しました。
aws entityresolution generate-match-id \
--workflow-name advanced-realtime-demo \
--records '[{
"inputSourceARN": "arn:aws:glue:ap-northeast-1:123456789012:table/entity_resolution_demo/customers",
"uniqueId": "c002",
"recordAttributeMap": {
"email": "hanako@example.com",
"phone": "+81-80-9876-5432"
}
}]' \
--region ap-northeast-1
c001、c005とは異なるmatchIdが発行され、matchRuleはNoRuleでした。
{
"matchGroups": [
{
"records": [
{
"inputSourceARN": "arn:aws:glue:ap-northeast-1:123456789012:table/entity_resolution_demo/customers",
"recordId": "c002"
}
],
"matchId": "d4dce0c6b0f348ecb61002b34602280e",
"matchRule": "NoRule"
}
],
"failedRecords": []
}
| レコード | phone | matchId(先頭8桁) | matchRule | |
|---|---|---|---|---|
| c001 | taro@example.com | +81-90-1234-5678 | 1e92cde4 | NoRule |
| c005 | taro@example.com | +81-90-1234-5678 | 1e92cde4 | email-and-phone |
| c002 | hanako@example.com | +81-80-9876-5432 | d4dce0c6 | NoRule |
OR 条件での動作確認
AND条件との動作の違いを確認するため、OR条件(Exact(Email) OR Exact(Phone))のワークフローを作成しました。
aws entityresolution create-matching-workflow \
--workflow-name advanced-realtime-demo-or \
--input-source-config '[{
"inputSourceARN": "arn:aws:glue:ap-northeast-1:123456789012:table/entity_resolution_demo/customers",
"schemaName": "advanced-realtime-demo-schema"
}]' \
--output-source-config '[{
"outputS3Path": "s3://entity-resolution-advanced-realtime-demo-20260723/output-or/",
"output": [
{"name": "unique_id", "hashed": false},
{"name": "name", "hashed": false},
{"name": "email", "hashed": false},
{"name": "phone", "hashed": false}
]
}]' \
--resolution-techniques '{
"resolutionType": "RULE_MATCHING",
"enableRealTimeMatching": true,
"ruleConditionProperties": {
"rules": [{
"ruleName": "email-or-phone",
"condition": "Exact(Email) OR Exact(Phone)"
}]
}
}' \
--role-arn arn:aws:iam::123456789012:role/EntityResolutionAdvancedRealtimeDemo \
--region ap-northeast-1
まずc001を投入し、一致相手がないためmatchRuleはNoRuleで新しいmatchIdが発行されました。
aws entityresolution generate-match-id \
--workflow-name advanced-realtime-demo-or \
--records '[{
"inputSourceARN": "arn:aws:glue:ap-northeast-1:123456789012:table/entity_resolution_demo/customers",
"uniqueId": "c001",
"recordAttributeMap": {
"email": "taro@example.com",
"phone": "+81-90-1234-5678"
}
}]' \
--region ap-northeast-1
次に、同じメールアドレスで電話番号だけが異なるc006を投入しました。
aws entityresolution generate-match-id \
--workflow-name advanced-realtime-demo-or \
--records '[{
"inputSourceARN": "arn:aws:glue:ap-northeast-1:123456789012:table/entity_resolution_demo/customers",
"uniqueId": "c006",
"recordAttributeMap": {
"email": "taro@example.com",
"phone": "+81-90-9999-0000"
}
}]' \
--region ap-northeast-1
c001と同じmatchIdが返り、matchRuleはemail-or-phoneでした。電話番号は異なりますが、メールアドレスが一致しているためOR条件でマッチしています。
OR条件でのレスポンス全文
c001投入時のレスポンス:
{
"matchGroups": [
{
"records": [
{
"inputSourceARN": "arn:aws:glue:ap-northeast-1:123456789012:table/entity_resolution_demo/customers",
"recordId": "c001"
}
],
"matchId": "e0449670d2104f64818a105660286eda",
"matchRule": "NoRule"
}
],
"failedRecords": []
}
c006投入時のレスポンス:
{
"matchGroups": [
{
"records": [
{
"inputSourceARN": "arn:aws:glue:ap-northeast-1:123456789012:table/entity_resolution_demo/customers",
"recordId": "c006"
}
],
"matchId": "e0449670d2104f64818a105660286eda",
"matchRule": "email-or-phone"
}
],
"failedRecords": []
}
StartMatchingJob の実行結果
aws entityresolution start-matching-job \
--workflow-name advanced-realtime-demo \
--region ap-northeast-1
InternalServerExceptionが返り、この検証ではバッチ処理を開始できませんでした。
StartMatchingJobのエラー出力
An error occurred (InternalServerException) when calling the StartMatchingJob operation: Internal Server Error
まとめ
AWS Entity Resolutionの高度なルールベースマッチングで、AND/OR条件を使ったリアルタイム照合をCLIから確認しました。
Exact(Email) AND Exact(Phone)では両属性が一致するレコードに、Exact(Email) OR Exact(Phone)では一方の属性が一致するレコードに、同じmatchIdが返りました。本検証では、初回バッチ処理を行わずにGenerateMatchIdを実行し、照合結果を取得できました。
リアルタイムに属性の一致、たとえば会員登録時のメールアドレスや電話番号の重複確認などを判定したい場面で選択肢に入りそうです。







