-
Notifications
You must be signed in to change notification settings - Fork 181
Description
Use case
This came up at one of our chalk talks at Re:Invent, where a customer wanted to know what to do if a password was rotated but the old version was cached in the lambda causing an authentication failure. While this example was specific to secrets manager, I think it is generalisable to any parameter that is retrieved where a stale cache value might cause some sort of error.
Currently users need to handle this themselves, most likely by surrounding the code that uses the parameter in a try/catch block and then implementing some retry logic. This strikes me a reasonably common use case and I'm opening this issue to see if there's a case to be made to add helper functions to the utility to handle this scenario.
Solution/User Experience
I envisage providing higher order functions that take the following parameters: a key name, a function that accepts one argument, the value of the retireved key, and an optional configuration object for handling retry behaviour and provider options, e.g., decrypt: true. The utility function will retrieve the parameter/secret and invoke the callback function with the result:
import { withParameter } from '@aws-lambda-powertools/parameters/ssm';
export const handler = (event, context) => {
// ...
const result = await withParameter('/my/microservice/url', (parameter) => {
const response = await fetch(parameter);
return response.json();
}, {decrypt: false});
// do something with result
}import { withSecret } from '@aws-lambda-powertools/parameters/secrets';
export const handler = (event, context) => {
// ...
const result = await withSecret('api-key', (secret) => {
const response = await fetch(someApi, {headers: {'x-api-key': secret}});
return response.json();
}, {retry: {times: 3}});
// do something with result
}There could be scope to allow users to provide a customer retry function, e.g., for exponential bckoffm but I have keep things simple for this discussion.
Alternative solutions
As mentioned, customers can roll their own error handling.Acknowledgment
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status