@InjectKeywordedSecretString - AWS Secrets Manager

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

@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')