Skip to content

feat(python): accept a credentials object for token signing - #19

Merged
mwaisaida-13 merged 2 commits into
release-2from
python/credentials-parameter
Oct 13, 2026
Merged

mwaisaida-13 merged 2 commits into
release-2from
python/credentials-parameter

Conversation

@shohamazon

@shohamazon shohamazon commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

What

Adds an optional credentials parameter to generate_iam_auth_token, ElastiCacheIAMAuthTokenProvider, and ElastiCacheIAMAuthTokenManager, so a caller can sign with a botocore credentials object it already holds instead of supplying a session.

generate_iam_auth_token(
    serverless_cache_name="my-cache",
    user_id="default.iam-user",
    region="us-east-1",
    credentials=credentials,   # instead of session=...
)

credentials takes precedence when both are given. Existing callers are unaffected.

Why

A client that integrates with an application's existing boto3 client has the credentials behind that client but not the session it was created from — a boto3 client keeps no reference back to one. Today the only way to sign a cache token with the application's own identity is to ask it for the session as well, which is an extra argument that exists purely to reach get_credentials().

The session was already used for just two things: get_credentials() and, as a last fallback, get_config_variable("region"). A caller that passes a region explicitly only needs the first.

Rotation is preserved

_resolve_credentials still re-reads per token request and calls get_frozen_credentials(), so a refreshable credentials object refreshes itself exactly as the session's would: the refresh callable is captured inside the object when the chain resolves it, so it needs nothing from the session afterwards. The new tests cover a RefreshableCredentials object vending rotated keys across two get_token() calls.

Lets a caller sign with a credentials object it already holds — the one
behind an existing boto3 client, for instance — instead of a session.
Credentials take precedence over the session and are still re-read per
token, so rotation is preserved.

@mwaisaida-13 mwaisaida-13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a clean addition! A few things before merge:

  • CHANGELOG, please add the new parameter under Unreleased / Added.

  • README. The Credentials section only describes the default chain. Could you add a short "bring your own credentials" paragraph with the snippet from the PR description?

@mwaisaida-13
mwaisaida-13 merged commit 7beb3b3 into release-2 Oct 13, 2026
14 checks passed
@shohamazon
shohamazon deleted the python/credentials-parameter branch October 13, 2026 11:34
shohamazon added a commit to awslabs/elasticache-integration-client that referenced this pull request Oct 15, 2026
Replaces the client() factory. The application builds its own client — profile,
botocore Config, endpoint — and install() hooks into it, so none of that has to
be mirrored here. The service name and region_name go with it: the service is in
the botocore event name, the region and credentials are on the client.

Bumps the IAM toolkit pin for its credentials parameter
(aws/developer-toolkit-elasticache#19). A failed bring-up no longer closes the
client, which is the caller's.
shohamazon added a commit to awslabs/elasticache-integration-client that referenced this pull request Oct 18, 2026
Replaces the client() factory. The application builds its own client — profile,
botocore Config, endpoint — and install() hooks into it, so none of that has to
be mirrored here. The service name and region_name go with it: the service is in
the botocore event name, the region and credentials are on the client.

Bumps the IAM toolkit pin for its credentials parameter
(aws/developer-toolkit-elasticache#19). A failed bring-up no longer closes the
client, which is the caller's.
shohamazon added a commit to awslabs/elasticache-integration-client that referenced this pull request Oct 18, 2026
* python: install into the application's own boto3 client

Replaces the client() factory. The application builds its own client — profile,
botocore Config, endpoint — and install() hooks into it, so none of that has to
be mirrored here. The service name and region_name go with it: the service is in
the botocore event name, the region and credentials are on the client.

Bumps the IAM toolkit pin for its credentials parameter
(aws/developer-toolkit-elasticache#19). A failed bring-up no longer closes the
client, which is the caller's.

* python: enforce a single install and clean up a failed one

A second install() is refused: botocore silently ignores a duplicate handler, so
the second session would run behind a handler that never fires. Closing restores
boto3's own close(), so install/close cycles do not stack. A failed hook install
now closes the session, which owns a connection and background threads.

Documents install() and the cache-side arguments, verify and ca_certs included.

* python: close the client even if detaching fails

_close() left the client open with our close() still installed if session.close()
raised. The detach steps now run in a try, and the client's own close is restored
and called in a finally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants