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

参考

相关推荐
RSTJ_162529 分钟前
PYTHON+AI LLM DAY THREETY-SEVEN
开发语言·人工智能·python
郝学胜-神的一滴33 分钟前
深度学习优化核心:梯度下降与网络训练全解析
数据结构·人工智能·python·深度学习·算法·机器学习
yyuuuzz33 分钟前
aws亚马逊入门常见认知误区
运维·服务器·网络·云计算·github·aws
Aision_42 分钟前
Agent 为什么需要 Checkpoint?
人工智能·python·gpt·langchain·prompt·aigc·agi
清水白石0081 小时前
《Python性能深潜:从对象分配开销到“小对象风暴”的破解之道(含实战与最佳实践)》
开发语言·python
Land03292 小时前
RPA工具选型技术指南:架构差异与实测数据
python·自动化·rpa
kafei_*2 小时前
VScode 添加 UV虚拟环境方法
vscode·python·uv
洛_尘3 小时前
Python 5:使用库
java·前端·python
m0_596749093 小时前
如何防止SQL拼接漏洞_使用PDO对象实现安全的SQL交互
jvm·数据库·python
AIFQuant5 小时前
2026 全球股票/外汇/贵金属行情 API 深度对比:延迟、覆盖、价格与稳定性
python·websocket·ai·金融·mcp