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

参考

相关推荐
happylifetree7 小时前
Python09:核心语法-数据存储与运算-字面量
python
心之语歌7 小时前
Tkinter 画布基本梳理
运维·服务器·python
Wx-bishekaifayuan8 小时前
django个性化旅游路线推荐平台49005-计算机课程设计、毕业设计
spring boot·后端·python·django·课程设计·express·旅游
小白快快跑哦9 小时前
python-字符串全解(六):正则表达式-量词
python·正则表达式·字符串
禹凕9 小时前
机器学习之Selenium(Machina Learning about Selenium)
爬虫·python·selenium·测试工具·机器学习
ebiobiz11 小时前
基于 GD32 Embedded Builder (GEB) 与 Nimmake 的 MCU 工程搭建指南
c++·python·单片机·嵌入式硬件·mcu
老歌老听老掉牙11 小时前
穿越时空的物流密码:VRP与VRPTW的深度剖析及实战求解
python·物流·vrp
FYKJ_201012 小时前
django电影推荐系统55066-计算机课程设计、毕业设计
vue.js·spring boot·python·mysql·typescript·spark·django
ShyanZh12 小时前
【Python3基础】13-Python 常用设计模式
开发语言·python·设计模式
小静AI工程实验室12 小时前
RSA 算法详解:从模幂原理到 OAEP 加密、PSS 签名与 Python 实验
python·算法