AWS Comprehend的同步调用(例如BatchDetectSentiment)会在CloudTrail中记录。CloudTrail是AWS的日志记录服务,它可以跟踪和记录AWS账户中的API调用和资源活动。
要查看AWS Comprehend同步调用的CloudTrail记录,可以按照以下步骤进行操作:
步骤1:打开CloudTrail控制台 登录到AWS管理控制台,然后导航到CloudTrail服务的控制台。
步骤2:选择CloudTrail跟踪 在CloudTrail控制台中,选择您要查看的CloudTrail跟踪。
步骤3:查看事件历史记录 在CloudTrail跟踪的“事件历史记录”选项卡下,您可以看到跟踪中记录的所有事件。
步骤4:筛选和搜索事件 使用筛选和搜索功能来找到您感兴趣的事件。您可以使用“事件名称”、“资源名称”、“服务名称”等筛选器来缩小范围。
步骤5:验证Comprehend事件 在搜索结果中,查找与AWS Comprehend相关的事件,并验证是否记录了BatchDetectSentiment等同步调用。
以下是使用AWS SDK for Python(Boto3)进行AWS Comprehend同步调用的示例代码:
import boto3
# 创建Comprehend客户端
comprehend_client = boto3.client('comprehend')
# 定义批量文本
text_list = [
'I love this product!',
'This is terrible.',
'The weather is nice today.'
]
# 调用BatchDetectSentiment接口
response = comprehend_client.batch_detect_sentiment(
TextList=text_list,
LanguageCode='en'
)
# 输出结果
print(response['ResultList'])
在上面的示例中,我们使用comprehend_client.batch_detect_sentiment
方法进行BatchDetectSentiment调用。当调用完成后,您应该能够在CloudTrail中找到相应的记录。
请注意,确保您已启用CloudTrail服务并配置了正确的日志记录设置,以便记录AWS Comprehend API调用。