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

参考

相关推荐
_Jimmy_8 小时前
Agent 溯源精度提升方案
人工智能·python·langchain
SamChan909 小时前
在Web应用中集成PDF多语言翻译功能:PDFTranslator API实战指南
前端·python·ai·pdf·yapi·机器翻译
天天进步20159 小时前
Python全栈项目--智能办公自动化系统
开发语言·python
颜酱10 小时前
09 | 重构项目结构
人工智能·python·langchain
kisloy11 小时前
【爬虫入门第8讲】Python爬虫反爬入门
开发语言·爬虫·python
Sisphusssss12 小时前
香橙派5plus GPIO
linux·python·ubuntu
颜酱12 小时前
08 | 把维度值同步到 Elasticsearch(生成阶段)
人工智能·python·langchain
久久学姐12 小时前
基础转码学 AI:Java+Python 双语言入门,3 个月可落地实战项目
java·python·ai·转码·实战项目
ZHOU_WUYI13 小时前
4. light wam 模型loss计算过程
开发语言·人工智能·python
nwsuaf_huasir13 小时前
【无标题】
python