Skip to content

AWS Lambda with Node 18.x and SDK v3 throws errors #213

@joelrwilliams12

Description

@joelrwilliams12

Currently lambda-api loads 'aws-sdk' in /lib/s3-service.js.

This fails with Node.js 18.x Lambda functions which are pre-loaded with SDK v3 and requires new syntax for loading SDK modules.

This throws the following error:

{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module 'aws-sdk'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/index.mjs",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module 'aws-sdk'",
        "Require stack:",
        "- /var/task/index.js",
        "- /var/runtime/index.mjs",
        "    at _loadUserApp (file:///var/runtime/index.mjs:1000:17)",
        "    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1035:21)",
        "    at async start (file:///var/runtime/index.mjs:1200:23)",
        "    at async file:///var/runtime/index.mjs:1206:1"
    ]
}

New syntax should be something like:

import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import { S3Client, getSignedUrl, GetObjectCommand } from "@aws-sdk/client-s3";

Documentation: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_s3_request_presigner.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions