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

如何通过非网页抓取方式获取AWS Marketplace所有数据产品元数据?

如何通过非网页抓取方式获取AWS Marketplace所有Data Products的元数据?

我想通过编程解析AWS Marketplace的「Data Products」目录,提取所有数据产品的描述等元数据并汇总,但尝试了两段boto3代码都只返回当前账户已订阅的内容,甚至返回的EntitySummaryList和DataSets为空:

第一段使用marketplace-catalog:

client = boto3.client('marketplace-catalog',
                      region_name='us-east-1')

response = client.list_entities(
    Catalog='AWSMarketplace',
    EntityType='DataProduct'
)

return response['EntitySummaryList']

第二段使用dataexchange:

client = boto3.client('dataexchange',
                       region_name='us-east-1'
)

response = client.list_data_sets()

return response['DataSets']

请问有没有无需网页抓取的实现方式?我知道可以用describe-images指定AWS Marketplace为所有者,但这个方案针对AMI,用来处理Data Products不够简洁。


解决方案

1. 修正marketplace-catalog的list_entities调用,添加公开产品筛选

默认情况下,list_entities仅返回当前账户有访问权限的实体(已订阅/自有产品)。要获取所有公开可用的Data Products,需要通过FilterList添加筛选条件,指定产品状态为Published且可见性为Public:

import boto3

client = boto3.client('marketplace-catalog', region_name='us-east-1')

response = client.list_entities(
    Catalog='AWSMarketplace',
    EntityType='DataProduct',
    FilterList=[
        {
            'Name': 'Status',
            'ValueList': ['Published']
        },
        {
            'Name': 'Visibility',
            'ValueList': ['Public']
        }
    ]
)

# 处理分页(如果结果超过100条)
all_entities = response['EntitySummaryList']
while 'NextToken' in response:
    response = client.list_entities(
        Catalog='AWSMarketplace',
        EntityType='DataProduct',
        FilterList=[
            {'Name': 'Status', 'ValueList': ['Published']},
            {'Name': 'Visibility', 'ValueList': ['Public']}
        ],
        NextToken=response['NextToken']
    )
    all_entities.extend(response['EntitySummaryList'])

# 获取每个产品的详细元数据
for entity in all_entities:
    entity_details = client.describe_entity(
        Catalog='AWSMarketplace',
        EntityId=entity['EntityId']
    )
    # 提取描述、名称等元数据
    product_name = entity_details['Details']['ProductName']
    product_description = entity_details['Details']['ShortDescription']
    # 后续写入文件等操作

2. 使用search_entities接口实现更灵活的筛选

如果需要按类别、关键词等更复杂的条件筛选,可以使用search_entities接口,支持类SQL的查询语句:

response = client.search_entities(
    Catalog='AWSMarketplace',
    EntityType='DataProduct',
    SearchQuery="Visibility='Public' AND Status='Published' AND ProductCategory='Data Products'"
)

关键说明

  • marketplace-catalog API仅在us-east-1区域可用,必须指定该区域
  • 调用API时有速率限制,建议添加重试逻辑或控制请求频率
  • list_entities默认返回最多100条结果,必须处理NextToken实现分页
  • 基础的EntitySummary只包含名称、ID等基本信息,详细描述等元数据需要调用describe_entity获取
  • dataexchange的list_data_sets接口仅针对AWS Data Exchange中账户已订阅或创建的数据集,无法获取Marketplace公开目录内容
  • describe-images确实仅适用于AMI产品,不适合Data Products场景

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 02:25:08