You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在AWS Lambda中用Boto3列取或获取Amazon Connect客户档案

解决Amazon Connect Customer Profiles 列出所有/获取单个档案的问题

一、核心误区纠正

你用的list_profile_objects不是用来列出客户档案的——这个API是获取单个客户档案关联的具体对象(比如从第三方同步过来的账户、联系人数据),所以必须传入ProfileId和ObjectTypeName。要列出所有客户档案,得用list_profiles方法。

二、列出所有客户档案的实现

使用list_profiles方法,无需预先知道ProfileId,只需要指定你的Customer Profiles域名:

import boto3

def lambda_handler(event, context):
    client = boto3.client('customer-profiles')
    domain_name = "你的Customer Profiles域名"  # 替换成实际域名
    
    all_profiles = []
    next_token = None
    
    # 分页拉取所有档案(默认单次最多返回100条)
    while True:
        request_params = {
            'DomainName': domain_name,
            'MaxResults': 100
        }
        if next_token:
            request_params['NextToken'] = next_token
            
        response = client.list_profiles(**request_params)
        all_profiles.extend(response['Items'])
        
        next_token = response.get('NextToken')
        if not next_token:
            break
    
    return {
        'statusCode': 200,
        'body': all_profiles
    }

三、获取单个客户档案详情

拿到ProfileId后,用get_profile方法获取单个档案的完整信息:

import boto3

def lambda_handler(event, context):
    client = boto3.client('customer-profiles')
    domain_name = "你的Customer Profiles域名"
    profile_id = event['profileId']  # 从Lambda事件参数或其他渠道传入ProfileId
    
    profile_detail = client.get_profile(
        DomainName=domain_name,
        ProfileId=profile_id
    )
    
    return {
        'statusCode': 200,
        'body': profile_detail
    }

四、list_profile_objects的正确用法

如果确实需要获取某个档案关联的外部同步数据,要先确认两点:

  1. 你的Customer Profiles域名下已经创建了对象类型(Object Type)——可通过AWS控制台查看,或调用put_profile_object_type创建自定义类型;
  2. 已有数据同步到该对象类型下,否则list_profile_object_types会返回空结果。

确认后,用从list_profiles拿到的ProfileId和对应ObjectTypeName调用:

response = client.list_profile_objects(
    DomainName=domain_name,
    ProfileId="从list_profiles获取的ID",
    ObjectTypeName="SalesforceAccount",  # 替换成实际对象类型名称
    MaxResults=100
)

五、权限注意事项

确保Lambda执行角色拥有以下权限:

  • customer-profiles:ListProfiles
  • customer-profiles:GetProfile
  • 若使用list_profile_objects,需额外添加customer-profiles:ListProfileObjects

内容的提问来源于stack exchange,提问作者GeoFox

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 13:07:42