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

如何在AWS Lambda中过滤client.describe_repositories()输出仅保留repositoryName?

解决方法

describe_repositories()返回的响应里,所有仓库的详细信息都存放在repositories数组中,每个仓库对象都包含repositoryName字段。你可以通过遍历这个数组,精准提取出需要的仓库名称:

修改后的代码如下:

import json
import boto3

def lambda_handler(event, context):
    
    client = boto3.client('ecr')
    response = client.describe_repositories()
    
    # 提取所有仓库名称并打印成列表
    repo_names = [repo['repositoryName'] for repo in response['repositories']]
    print(repo_names)
    
    # 也可以选择逐个打印每个仓库名称
    # for repo in response['repositories']:
    #     print(repo['repositoryName'])
    
    return {
        'body': json.dumps("hello world")
    }

这样就能过滤掉其他冗余信息,只输出你需要的repositoryName内容。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 01:05:22