@InjectKeywordedSecretString - Amazon Secrets Manager
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

@InjectKeywordedSecretString

此装饰器需要一个密钥 ID 字符串和 SecretCache 作为前两个参数。其余自变量将已包装函数中的参数映射到密钥中的 JSON 键。密钥必须包含一个 JSON 结构的字符串。

对于包含此 JSON 的密钥:

{ "username": "saanvi", "password": "EXAMPLE-PASSWORD" }

下面的示例演示了如何从密钥中提取 usernamepassword 的 JSON 值。

from aws_secretsmanager_caching import SecretCache from aws_secretsmanager_caching import InjectKeywordedSecretString, InjectSecretString cache = SecretCache() @InjectKeywordedSecretString ( secret_id = 'mysecret' , cache = cache , func_username = 'username' , func_password = 'password' ) def function_to_be_decorated( func_username, func_password): print( 'Do something with the func_username and func_password parameters')