Open dbligh opened 7 months ago
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.
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