Repository navigation
feat(node): add auto-refresh #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
506c0ef
feat(node): add auto-refresh
edlng e9f0bb3
feat(node): apply review changes
edlng b827d73
fix(node): format
edlng dddba17
fix(node): address comment
edlng d26b526
fix(node): address comments
edlng 8ae6eaf
Merge branch 'release-2' into node/auto-refresh
edlng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /* global console */ | ||
|
|
||
| /** | ||
| * Run this example after installing redis: | ||
| * | ||
| * npm install redis | ||
| * | ||
| * The cache name used for signing is different from the connection endpoint. | ||
| * For a node-based deployment, use replicationGroupId instead. | ||
| * | ||
| * node-redis calls an AsyncCredentialsProvider's credentials() on every | ||
| * connection handshake, including its own automatic reconnects. Backing it | ||
| * with ElastiCacheIAMAuthTokenManager.getCredentials() means every handshake | ||
| * gets a valid cached token without signing a new one per connection, and | ||
| * node-redis's built-in reconnect strategy can stay enabled. | ||
| */ | ||
| import { createClient } from "redis"; | ||
| import { ElastiCacheIAMAuthTokenManager } from "@aws/developer-toolkit-elasticache"; | ||
|
|
||
| const ENDPOINT = "my-cache-abc123.serverless.use1.cache.amazonaws.com"; | ||
|
|
||
| const auth = await ElastiCacheIAMAuthTokenManager.create({ | ||
| serverlessCacheName: "my-cache", | ||
| userId: "my-iam-user", | ||
| region: "us-east-1", | ||
| // Never log the token itself; it is a bearer credential. | ||
| onTokenChanged: () => console.log("installed a new IAM auth token"), | ||
| }); | ||
|
|
||
| const client = createClient({ | ||
| socket: { | ||
| host: ENDPOINT, | ||
| port: 6379, | ||
| tls: true, | ||
| }, | ||
| credentialsProvider: { | ||
| type: "async-credentials-provider", | ||
| credentials: async () => { | ||
| const [username, password] = await auth.getCredentials(); | ||
| return { username, password }; | ||
| }, | ||
| }, | ||
| }); | ||
| client.on("error", (error) => console.error("node-redis client error", error)); | ||
|
|
||
| try { | ||
| await client.connect(); | ||
| await client.set("hello", "world"); | ||
| console.log(await client.get("hello")); | ||
| } finally { | ||
| await client.close(); | ||
| auth.close(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: since iovalkey only takes a static password, this example still has to disable reconnects, so the manager's main benefit isn't visible. Could we add a second example with node-redis v5, whose
credentialsProvider: { type: "async-credentials-provider", credentials: () => auth.getCredentials().then(([username, password]) => ({ username, password })) }is called on every connect and reconnect? Keep this one as the static-password variant.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added