AWS Builder Center: Learn, Build and Connect with builders in the AWS community
AWS Builder Center is the official home for builders on AWS. Share and read what others are working on, follow people who inspire you, explore training and workshops, and find tools to support what you're building.
如何為 Amazon Pinpoint SMS 和 Voice v1 API 設定 Amazon Pinpoint 語音訊息的日誌記錄?
我想監控透過 Amazon Pinpoint 傳送的語音訊息之狀態。該如何設定?
簡短描述
要記錄 Amazon Pinpoint 語音訊息的狀態,您必須設定事件目的地。設定事件目的地後,它會收到有關您透過 Amazon Pinpoint 傳送的語音訊息的回應資訊。
您可以將以下任何 AWS 資源設定為 Amazon Pinpoint 語音事件目的地:
- Amazon Simple Notification Service (Amazon SNS) 主題
- Amazon CloudWatch Logs
- Amazon Kinesis Data Firehose 串流
要設定事件目的地,可以使用 Amazon Pinpoint SMS 和語音訊息 API 或其中一個 AWS SDK。
**注意:**以下解決方案僅適用於 Amazon Pinpoint SMS 和 Voice v1 API。關於 Amazon Pinpoint SMS 和 Voice v2 API,請參閱如何為 Amazon Pinpoint SMS 和 Voice v2 API 設定 Amazon Pinpoint 語音訊息的日誌記錄?
解決方案
以下範例程序演示如何使用 Amazon Pinpoint SMS 和語音訊息 API 來建立事件目的地。要使每個範例設定起作用,您必須使用 SendVoiceMessage API 操作來傳送語音訊息。API 請求還必須在 ConfigurationSetName 參數中傳遞您的組態集的名稱。有關程式碼範例,請參閲《Amazon Pinpoint 開發人員指南》中的傳送語音訊息。
**注意:**如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤訊息,請確保您使用的是最新的 AWS CLI 版本。如果在完成上述任何程序後語音日誌仍未填充,請參閲以下文章:《為什麼我的 Amazon Pinpoint 語音訊息日誌未填充?》
將 Amazon SNS 主題設定為 Amazon Pinpoint 語音事件目的地
1. 請確保 SNS 主題的存取政策包含以下許可。這可允許 Amazon Pinpoint 伺服器交付日誌:
{ "Sid": "pinpointsmsvoice", "Effect": "Allow", "Principal": { "Service": "sms-voice.amazonaws.com" }, "Action": "SNS:Publish", "Resource": "arn:aws:sns:us-west-2:XXXXXX:pinpointsmsvoice" }
2. 透過執行以下 create-configuration-set AWS CLI 命令建立組態集:
**注意:**您可以將 VoiceSNS 替換為組態集的任何名稱。
aws pinpoint-sms-voice create-configuration-set --configuration-set-name VoiceSNS
3. 將您想要接收語音訊息日誌的端點訂閲至現有 Amazon SNS 主題或新主題。如需指示,請參閱《Amazon SNS 開發人員指南》中的將端點訂閲至 Amazon SNS 主題。
**注意:**要使用 AWS CLI 建立新的 Amazon SNS 主題,請執行以下 create-topic 命令:
aws sns create-topic --name pinpointsmsvoice
4. 在文字編輯器中,建立名為 SNSDestination.json 的輸入請求檔案。然後,將以下目的地參數複製並貼到檔案中:
重要提示:將 替換為您的 AWS 區域。將 替換為您的 AWS 帳戶 ID。將 pinpointsmsvoice 替換為您的 Amazon SNS 主題的名稱。您可以編輯 MatchingEventTypes 值,以便僅包括要記錄的事件類型。
{ "Enabled": true, "MatchingEventTypes": ["INITIATED_CALL", "RINGING", "ANSWERED", "COMPLETED_CALL", "BUSY", "FAILED", "NO_ANSWER"], "SnsDestination": { "TopicArn": "arn:aws:sns:<region>:<AccountID>:pinpointsmsvoice" } }
5. 透過執行以下 create-configuration-set-event-destination 命令,將組態集映射到目的地參數:
**重要提示:**請確保將 VoiceSNS 替換為組態集的名稱。
aws pinpoint-sms-voice create-configuration-set-event-destination --configuration-set-name VoiceSNS --event-destination-name SNS_Destination --event-destination file://SNSDestination.json
6. 透過使用 SendVoiceMessage API 操作傳送 Amazon Pinpoint 語音訊息來測試設定。幾分鐘後,事件將出現在訂閲至 Amazon SNS 主題的端點中。
**重要提示:**請確保 API 請求的 ConfigurationSetName 參數與組態集的名稱匹配。
將 CloudWatch Logs 設定為 Amazon Pinpoint 語音事件目的地
1. 透過執行以下 create-configuration-set AWS CLI 命令建立組態集:
**注意:**您可以將 VoiceCW 替換為您的組態集的任何名稱。
aws pinpoint-sms-voice create-configuration-set --configuration-set-name VoiceCW
2. 透過執行以下 create-log-group 命令,建立一個新的 CloudWatch 日誌群組以接收語音訊息日誌:
aws logs create-log-group --log-group-name /aws/pinpoint/voice
-或-
使用現有的 CloudWatch 日誌群組完成以下步驟。
3. 透過執行以下操作獲取 CloudWatch 日誌群組的 ARN:
開啟 CloudWatch 主控台。
在左側導覽窗格中,選擇 Logs (日誌)。然後,選擇 Log groups (日誌群組)。
在 Log group (日誌群組) 欄中,選擇日誌群組的名稱。
在 Log group details (日誌群組詳細資訊) 窗格中,複製 ARN 值。這是您的日誌群組的 ARN。
4. 為 Amazon Pinpoint 服務建立要承擔的新的 AWS Identity and Access Management (IAM) 角色。如需指示,請參閱為 AWS 服務建立角色 (主控台) 或為服務建立角色 (AWS CLI)。設定角色時,請修改角色的信任政策,以便在政策的主體部分中包含以下許可聲明:
**注意:**此許可聲明允許 sms-voice 服務承擔 IAM 角色。
{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Principal": { "Service": "sms-voice.amazonaws.com" }, "Action": "sts:AssumeRole" }] }
5. 修改 IAM 角色的許可政策,使其包含以下許可聲明:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "logs:CreateLogStream", "logs:CreateLogGroup", "logs:DescribeLogStreams", "logs:PutLogEvents" ], "Resource": "arn:aws:logs:*:*:*" } ] }
**注意:**此許可聲明授予呼叫特定 CloudWatch Logs API 操作的許可。如需詳細資訊,請參閱 CloudWatch Logs 許可參考。
6. 在文字編輯器中,建立名為 CloudWatchDestination.json 的輸入請求檔案。然後,將以下目的地參數複製並貼到檔案中:
重要提示:將 替換為您的 AWS 區域。將 替換為您的 AWS 帳戶 ID。將 替換為 IAM 角色名稱。您可以編輯 MatchingEventTypes 值,以便僅包括要記錄的事件類型。
{ "Enabled": true, "MatchingEventTypes": ["INITIATED_CALL", "RINGING", "ANSWERED", "COMPLETED_CALL", "BUSY", "FAILED", "NO_ANSWER"], "CloudWatchLogsDestination": { "LogGroupArn": "arn:aws:logs:<region>:<AccountID>:log-group/aws/pinpoint/voice:*", "IamRoleArn": "arn:aws:iam::<AccountID>:role/<IAM role name>" } }
7. 透過執行以下 create-configuration-set-event-destination 命令,將組態集映射到目的地參數:
**重要提示:**請確保將 VoiceCW 替換為組態集的名稱。
aws pinpoint-sms-voice create-configuration-set-event-destination --configuration-set-name VoiceCW --event-destination-name CloudWatch_Destination --event-destination file://CloudWatchDestination.json
8. 透過使用 SendVoiceMessage API 操作傳送 Amazon Pinpoint 語音訊息來測試設定。幾分鐘後,事件將出現在 CloudWatch 日誌群組中。
將 Kinesis Data Firehose 串流設定為 Amazon Pinpoint 語音事件目的地
1. 透過執行以下 create-configuration-set AWS CLI 命令建立組態集:
**注意:**您可以將 VoiceKinesis 替換為組態集的任何名稱。
aws pinpoint-sms-voice create-configuration-set --configuration-set-name VoiceKinesis
2. 建立 Kinesis Data Firehose 交付串流。對於 Destination (目的地) 設定,請選擇 Amazon Simple Storage Service (Amazon S3)。
**重要提示:**接受預設 IAM 服務角色。然後,將 IAM 服務角色的名稱複製到剪貼簿。您需要執行以下步驟的角色名稱。
3. 修改預設 IAM 服務角色的信任政策,以便在政策的主體部分中包含以下許可聲明:
**注意:**此許可聲明授予 sms-voice 服務承擔 IAM 角色。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": [ "firehose.amazonaws.com", "sms-voice.amazonaws.com" ] }, "Action": "sts:AssumeRole" } ] }
4. 修改 IAM 服務角色的許可政策,使其包含以下許可聲明:
**重要提示:**不要刪除 IAM 服務角色的任何預設許可聲明。
{ "Sid": "VisualEditor0", "Effect": "Allow", "Action": "firehose:*", "Resource": "*" },
5. 在文字編輯器中,建立名為 KinesisFirehoseDestination.json 的輸入請求檔案。然後,將以下目的地參數複製並貼到檔案中:
重要提示:將 替換為您的 AWS 區域。將 替換為您的 AWS 帳戶 ID。將 Name_of_Kinesis_Firehose 替換為 Amazon Kinesis Data Firehose 串流的名稱。將 替換為您的 IAM 角色名稱。您可以編輯 MatchingEventTypes 值,以便僅包括要記錄的事件類型。
{ "Enabled": true, "MatchingEventTypes": ["INITIATED_CALL","RINGING","ANSWERED","COMPLETED_CALL","BUSY","FAILED","NO_ANSWER"], "KinesisFirehoseDestination": { "DeliveryStreamArn": "arn:aws:firehose:<region>:<AccountID>:deliverystream/<Name_of_Kinesis_Firehose>", "IamRoleArn": "arn:aws:iam::<AccountID>:role/service-role/<IAM role name>" } }
6. 透過執行以下 create-configuration-set-event-destination 命令,將組態集映射到目的地參數:
**重要提示:**請確保將 VoiceKinesis 替換為組態集的名稱。
aws pinpoint-sms-voice create-configuration-set-event-destination --configuration-set-name VoiceKinesis --event-destination-name KinesisFirehose_Destination --event-destination file://KinesisFirehoseDestination.json
7. 透過使用 SendVoiceMessage API 操作傳送 Amazon Pinpoint 語音訊息來測試設定。幾分鐘後,事件將出現在您建立 Kinesis Data Firehose 串流時設定的 Amazon S3 儲存貯體中。
- 語言
- 中文 (繁體)

相關內容
AWS 官方已更新 1 年前