Skip to content

NodeJS Durable functions error

0

Hi, The example here with NodeJS 24 in us-east-1 or eu-central-1, tested from console: https://docs.aws.amazon.com/lambda/latest/dg/durable-basic-concepts.html import { DurableContext, withDurableExecution, } from "@aws/durable-execution-sdk-js";

export const handler = withDurableExecution( async (event: any, context: DurableContext) => { const result = await context.step(async () => { return "step completed"; }); return result; }, );

is currently failing with: Calling the invoke API action failed with this message: { "errorMessage": "SyntaxError: The requested module '@aws/durable-execution-sdk-js' does not provide an export named 'DurableContext'", "errorType": "Runtime.UserCodeSyntaxError" }

To fix the issue: import * as durableSDK from '@aws/durable-execution-sdk-js'; const { withDurableExecution, DurableContext } = durableSDK;

Thank you, Lucian

asked 10 months ago174 views

1 Answer
0

You're right about the import issue with the AWS Lambda durable functions example. The error occurs because the import statement in the example is not correctly accessing the exports from the @aws/durable-execution-sdk-js module.

The fix you've provided is correct. Instead of using named imports directly, you can use the following approach:

import * as durableSDK from '@aws/durable-execution-sdk-js';
const { withDurableExecution, DurableContext } = durableSDK;

export const handler = withDurableExecution(
async (event: any, context: DurableContext) => {
const result = await context.step(async () => {
return "step completed";
});
return result;
},
);

This approach first imports the entire module as durableSDK and then extracts the specific functions and types you need. This works because it properly accesses the exports provided by the durable execution SDK.

Alternatively, you could also check the module's actual export structure and adjust your imports accordingly, as the SDK's export interface might have changed since the documentation was written.
Sources
Basic concepts - AWS Lambda

answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.