The `aws-secretsmanager-caching` library provides a client-side caching solution for AWS Secrets Manager. It helps reduce API calls to Secrets Manager, improving application performance and potentially lowering costs, by storing secret values in memory for a configurable duration. The current version is 1.1.3 and it is actively maintained by AWS.
pip install aws-secretsmanager-cachingVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `SecretCache` with optional configuration, retrieve a secret, and observe the caching behavior. Ensure your AWS credentials and region are configured (e.g., via environment variables or AWS CLI configuration) for `boto3` to work correctly. The `os.environ.get` calls are for demonstration purposes; replace `'my-test-secret'` with an actual secret name.
Carefully consider your application's tolerance for stale data versus API call frequency. For rapidly changing secrets, use a lower TTL. For critical secrets where staleness is unacceptable, you might need to rely on `refreshNow()` or avoid aggressive caching. Understand the difference between `ttl` and `stall_time` in `SecretCacheConfig`.
Explicitly pass a `boto3` Secrets Manager client to `SecretCache(client=...)` that is initialized with the desired region. Verify the IAM role/user credentials have `secretsmanager:GetSecretValue` permissions for the target secrets.
Upgrade `setuptools` to a recent version if encountering import or distribution issues related to metadata. For most users, this change is internal and will not require action, but it's a good practice to test thoroughly after upgrading.
This is expected behavior. If shared caching is required, an external caching layer (e.g., Redis) would be necessary, but this library is specifically for client-side in-memory caching. Design your application's scaling to account for individual cache warm-up.
Install the package using pip: 'pip install aws-secretsmanager-caching'.
Ensure the IAM policy attached to the user or role includes 'secretsmanager:GetSecretValue' permission.
Verify the secret name or ARN is correct and that the secret exists in the specified AWS region.
Initialize the SecretCache class with the correct parameters: 'cache = SecretCache(config=cache_config, client=client)'.
Configure AWS credentials using the AWS CLI with 'aws configure' or set environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.