Skip to content
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

Not compatible with Node 18 on Lambda due to aws-sdk3 #17

Open
dbligh opened this issue Jan 31, 2024 · 1 comment
Open

Not compatible with Node 18 on Lambda due to aws-sdk3 #17

dbligh opened this issue Jan 31, 2024 · 1 comment

Comments

@dbligh
Copy link

dbligh commented Jan 31, 2024

Using this library doesn't seem to play nicely in the Lambda Node 18 runtime.

{ "errorType": "Runtime.ImportModuleError", "errorMessage": "Error: Cannot find module 'aws-sdk'\nRequire stack:\n- /var/task/node_modules/serverless-dynamodb-client/index.js\n- /var/task/handlers/profile.js\n- /var/runtime/index.mjs", "stack": [ "Runtime.ImportModuleError: Error: Cannot find module 'aws-sdk'", "Require stack:", "- /var/task/node_modules/serverless-dynamodb-client/index.js", "- /var/task/handlers/profile.js", "- /var/runtime/index.mjs", " at _loadUserApp (file:///var/runtime/index.mjs:1087:17)", " at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)", " at async start (file:///var/runtime/index.mjs:1282:23)", " at async file:///var/runtime/index.mjs:1288:1" ] }

This may need to be adjusted to import DynamoDB in a way that's compatible with aws-sdk v3
https://github.com/aws/aws-sdk-js-v3

@dbligh
Copy link
Author

dbligh commented Feb 1, 2024

Work around at the moment is to use a class similar to this:


const HOST = process.env.LOCAL_DDB_HOST || "localhost";
const PORT = process.env.LOCAL_DDB_PORT || 8000;
const ENDPOINT = process.env.LOCAL_DDB_ENDPOINT || `http://${HOST}:${PORT}`;

const OFFLINE_OPTIONS = {
  region: "localhost",
  endpoint: ENDPOINT,
  accessKeyId: "MOCK_ACCESS_KEY_ID",
  secretAccessKey: "MOCK_SECRET_ACCESS_KEY",
};

const IS_OFFLINE = process.env.IS_OFFLINE || process.env.IS_LOCAL;

class OfflineDynamoDB extends DynamoDBClient {
  constructor(options: DynamoDBClientConfig) {
    super({ ...options, ...OFFLINE_OPTIONS });
  }
}

export const DynamoDB = IS_OFFLINE ? OfflineDynamoDB : DynamoDBClient;```

This is a breaking change to your code that uses this library though.

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

No branches or pull requests

1 participant