generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 181
Labels
feature-requestThis item refers to a feature request for an existing or new utilityThis item refers to a feature request for an existing or new utilityidempotencyThis item relates to the Idempotency UtilityThis item relates to the Idempotency Utilitypending-releaseThis item has been merged and will be released soonThis item has been merged and will be released soon
Description
Expected Behavior
Idempotency Utility works correctly when a durable function is suspended and replayed
Current Behavior
- Idempotency utility breaks in some Lambda durable executions
- Will raise IdempotencyAlreadyInProgressError if a durable execution is suspended and then replayed, such as after a
context.wait()call - Identified as a duplicate of an existing payload, rather than a replay of the original payload (which should be allowed)
Code snippet
import {
withDurableExecution,
DurableContext,
} from "aws-durable-execution-sdk-js";
import {
IdempotencyConfig,
makeIdempotent,
} from "@aws-lambda-powertools/idempotency";
import { DynamoDBPersistenceLayer } from "@aws-lambda-powertools/idempotency/dynamodb";
const persistenceStore = new DynamoDBPersistenceLayer({
tableName:
process.env.IDEMPOTENCY_TABLE_NAME || "powertools-idempotency-table",
});
const innerHandler = async (event, context: DurableContext) => {
config.registerLambdaContext(context.lambdaContext);
try {
console.log({ event });
// This breaks the idempotency function as
// the replay detects the existing "in progress" execution,
// so throws an IdempotencyAlreadyInProgressError error.
await context.wait("wait", 60);
const processedData = await context.step(async () => {
// Simulating idempotent operation
return {
id: "unique-id",
timestamp: Date.now(),
};
});
context.step(async () => {
// Additional processing step
console.log("Processing data:", processedData);
});
return {
statusCode: 200,
body: JSON.stringify({
message: "Success",
data: processedData,
}),
};
} catch (error) {
console.error(error);
console.trace();
return {
statusCode: 500,
body: JSON.stringify({
message: "Error",
error: error instanceof Error ? error.message : "Unknown error",
}),
};
}
};
export const handler = withDurableExecution(
makeIdempotent(innerHandler, {
persistenceStore,
})
);Steps to Reproduce
- Create a lambda function with a durable config specified, and the handler above
- Invoke the function
- Observe an error is raised
Possible Solution
No response
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
24.x
Packaging format used
npm
Execution logs
Metadata
Metadata
Assignees
Labels
feature-requestThis item refers to a feature request for an existing or new utilityThis item refers to a feature request for an existing or new utilityidempotencyThis item relates to the Idempotency UtilityThis item relates to the Idempotency Utilitypending-releaseThis item has been merged and will be released soonThis item has been merged and will be released soon
Type
Projects
Status
Coming soon