@InjectKeywordedSecretString
このデコレータは、1 番目と 2 番目の引数として、シークレット ID 文字列と SecretCache を必要とします。残りの引数は、ラップされた関数のパラメータをシークレット内の JSON キーにマッピングします。シークレットに JSON 構造の文字列が含まれている必要があります。
この JSON を含むシークレットの場合は、次のようになります。
{ "username": "saanvi", "password": "EXAMPLE-PASSWORD" }
次の例では、シークレットから username および password の 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' ) deffunction_to_be_decorated( func_username, func_password): print( 'Do something with the func_username and func_password parameters')