AWS Glue Python Shell任务中获取AWS SM中的加密配置

问题

需要再AWS Glue Python Shell中获取敏感配置。这里通过boto3客户端获取。

Python

python 复制代码
import boto3
import json

"""使用 boto3 直接从 Secrets Manager 获取配置"""
try:
    # 创建 Secrets Manager 客户端
    client = boto3.client('secretsmanager')
    
    # 获取 Secret 值
    response = client.get_secret_value(SecretId=secret_arn)
    
    # 判断返回的是字符串还是二进制(通常是字符串形式的 JSON)
    if 'SecretString' in response:
        secret = json.loads(response['SecretString'])
    else:
        # 如果是二进制数据,需要先解码
        secret = json.loads(base64.b64decode(response['SecretBinary']))
        
    # 校验字段
    required = ['你配置的key', '你配置的key2']
    for field in required:
        if field not in secret:
            raise ValueError(f"Secret 中缺少字段: {field}")
    
    logger.info("成功通过 boto3 获取 AES 配置")
    return secret
    
except Exception as e:
    logger.exception(f"通过 boto3 获取 Secret 失败: {str(e)}")
    raise

参考

相关推荐
A小辣椒17 小时前
AWS Clould Support Engineer就职面试题
aws
星云穿梭17 小时前
用Python写一个带图形界面的学生管理系统——完整教程
python
金銀銅鐵18 小时前
用 Pygame 实现 15 puzzle
python·数学·游戏
黄忠1 天前
大模型之LangGraph技术体系
python·llm
hboot2 天前
AI工程师第二课 - 数据处理
人工智能·python·数据分析
用户8356290780512 天前
使用 Python 自动化 PowerPoint 形状布局与格式设置
后端·python
用户8356290780512 天前
用 Python 自动化 PowerPoint 演讲者备注添加
后端·python
黄忠2 天前
01-系统架构设计-LangGraph状态机与多源异构RAG
python
zzzzzz3102 天前
假如我是掘金管理员,我先给评论区装个'代码审查'系统
python·程序员·机器人
砍材农夫2 天前
python环境|conda安装和使用(2)
后端·python