如何使用 AWS Lambda 和 Python 获取 EMR 集群的标签列表

本文介绍如何通过 boto3 的 describe_cluster 方法在 AWS Lambda 中高效获取 Amazon EMR 集群的全部标签,替代不存在的 get_tags 接口,并提供可直接部署的示例代码与关键注意事项。 本文介绍如何通过 boto3 的 `describe_cluster` 方法在 aws lambda 中高效获取 amazon emr 集群的全部标签,替代不存在的 `get_tags` 接口,并提供可直接部署的示例代码与关键注意事项。Amazon EMR 并未提供类似 S3 的 get_bucket_tagging 这样专用于标签查询的独立 API,但其集群元数据中完整包含了标签信息。核心方法是调用 describe_cluster ------ 该接口不仅返回集群状态、配置和硬件信息,还将所有用户定义的标签以结构化形式嵌套在 response'Cluster''Tags' 中,是当前唯一官方支持且稳定的标签获取方式。以下是一个可在 AWS Lambda 中直接运行的完整 Python 示例(基于 boto3):import boto3import jsondef lambda_handler(event, context): # 从事件或环境变量中获取集群 ID(推荐通过 event 传入,提升灵活性与安全性) cluster_id = event.get('ClusterId') if not cluster_id: return { 'statusCode': 400, 'body': json.dumps({'error': 'Missing required parameter: ClusterId'}) } try: emr_client = boto3.client('emr', region_name='us-east-1') # 请根据实际区域调整 response = emr_client.describe_cluster(ClusterId=cluster_id) # 提取标签列表(格式为 {'Key': 'Name', 'Value': 'prod-emr'}, ...) tags = response'Cluster'.get('Tags', \[\]) return { 'statusCode': 200, 'body': json.dumps({ 'ClusterId': cluster_id, 'Tags': tags, 'TagCount': len(tags) }) } except emr_client.exceptions.ClusterNotFound: return { 'statusCode': 404, 'body': json.dumps({'error': f'EMR cluster {cluster_id} not found'}) } except Exception as e: return { 'statusCode': 500, 'body': json.dumps({'error': str(e)}) }? 关键注意事项: Adobe Image Background Remover Adobe推出的图片背景移除工具

相关推荐
星云穿梭6 小时前
用Python写一个带图形界面的学生管理系统——完整教程
python
金銀銅鐵6 小时前
用 Pygame 实现 15 puzzle
python·数学·游戏
倔强的石头_11 小时前
《Kingbase护城河》——数据库存储空间全景探测与精细化瘦身实战
数据库
黄忠11 小时前
大模型之LangGraph技术体系
python·llm
冬奇Lab1 天前
每日一个开源项目(第134篇):Zvec - 阿里开源的嵌入式向量数据库,向量搜索界的 SQLite
数据库·人工智能·llm
hboot1 天前
AI工程师第二课 - 数据处理
人工智能·python·数据分析
用户8356290780511 天前
使用 Python 自动化 PowerPoint 形状布局与格式设置
后端·python
用户8356290780511 天前
用 Python 自动化 PowerPoint 演讲者备注添加
后端·python
ClouGence1 天前
Oracle CDC 架构优化:从主库直连到 DataGuard 备库同步
数据库·后端·oracle
黄忠2 天前
01-系统架构设计-LangGraph状态机与多源异构RAG
python