aws-sdk-js-v3 icon indicating copy to clipboard operation
aws-sdk-js-v3 copied to clipboard

Error when importing `client-dynamodb` module in AWS Lambda

Open GJZwiers opened this issue 3 years ago • 10 comments

Describe the bug

I was trying to use this module in an AWS Lambda handler running Deno. Importing the AWS DynamoDB Client using import * as dynamodb from "https://deno.land/x/aws_sdk/client-dynamodb/mod.ts"; is not successful but hangs for a number of seconds and fails. On viewing the logs in AWS CloudWatch the following Error is listed:

error: Uncaught SyntaxError: The requested module '../types/mod.ts' does not provide an export named 'Credentials' 
import { Credentials, Provider } from "../types/mod.ts";
~~~~~~~~~~~
at <anonymous> (<https://deno.land/x/[email protected]/client-sts/defaultStsRoleAssumers.ts>:1:1)

Your environment

Steps to reproduce

  • Deploy an AWS Lambda with Deno runtime according to this quickstart.
  • Import client in handler with import * as dynamodb from "https://deno.land/x/aws_sdk/client-dynamodb/mod.ts";
  • Test handler on AWS Lambda
  • Test reports failure, viewing logs shows the error.

Additional context

The handler code looks as follows:

import { APIGatewayProxyEventV2, APIGatewayProxyResultV2, Context } from "https://deno.land/x/[email protected]/mod.ts";
import * as dynamodb from "https://deno.land/x/aws_sdk/client-dynamodb/mod.ts";

  
// deno-lint-ignore require-await
export async function handler(_event: APIGatewayProxyEventV2, _context: Context): Promise<APIGatewayProxyResultV2> {

    const client = new dynamodb.DynamoDB({ apiVersion: 'latest' });

    await client.createTable({
        TableName: 'deno-test',
        KeySchema: [
            { AttributeName: 'id', KeyType: 'HASH' },
            { AttributeName: 'rate', KeyType: 'RANGE' }
        ],
        AttributeDefinitions: [
            { AttributeName: 'id', AttributeType: 'S' },
            { AttributeName: 'rate', AttributeType: 'N' }
        ],
        ProvisionedThroughput: {
            ReadCapacityUnits: 3,
            WriteCapacityUnits: 3
        }
    });

    return {
        statusCode: 200,
        headers: { "content-type": "text/html;charset=utf8" },
        body: `Powered by deno ${Deno.version.deno} 🦕`,
    };
}

GJZwiers avatar Apr 29 '21 14:04 GJZwiers

Sorry for the late reply. Can you reproduce that with the latest version?

christophgysin avatar May 26 '21 13:05 christophgysin

I've tried it with the latest version but the error remains. Here's the last few lines from the CloudWatch Logs:

Download https://deno.land/x/[email protected]/client-sso/endpoints.ts
Download https://deno.land/[email protected]/encoding/base64.ts
Download https://deno.land/[email protected]/encoding/hex.ts
error: Uncaught SyntaxError: The requested module '../types/mod.ts' does not provide an export named 'Credentials'
import { Credentials, Provider } from "../types/mod.ts";
at <anonymous> (<https://deno.land/x/[email protected]/client-sts/defaultStsRoleAssumers.ts>:3:1)

GJZwiers avatar May 27 '21 17:05 GJZwiers

I just encountered this tonight as well with version 3.22.0-1

error: Uncaught SyntaxError: The requested module '../types/mod.ts' does not provide an export named 'Credentials'
import { Credentials, Provider } from "../types/mod.ts";
         ~~~~~~~~~~~
    at <anonymous> (https://deno.land/x/[email protected]/client-sts/defaultStsRoleAssumers.ts:3:10)

CoeusCC avatar Jul 24 '21 03:07 CoeusCC

I'm not certain what the issue is, but this seems to be related: https://github.com/nodejs/node/issues/32137

I know Deno handles modules differently than Node, but I'm still pretty new to this approach, so not sure if it's actually related.

CoeusCC avatar Jul 24 '21 04:07 CoeusCC

Worth noting that if I compile and try to run, I get a host of different errors. I think there might be something to the idea that running the script uncompiled (using deno run file.ts from the command line) could not be handling module exports the way one might expect.

Not sure if that's expected, but it did get me beyond the bug mentioned above.

CoeusCC avatar Jul 24 '21 16:07 CoeusCC

For the dynamoDB tutorial on deno.land (https://deno.com/deploy/docs/tutorial-dynamodb#setup-dynamodb), I've swapped out skypack for this library, and managed to get past all the errors mentioned above by doing the following:

deno compile --reload --no-check --allow-env --allow-read --unstable index.ts

No check avoids the strict TS checks, allow-env is necessary for loading .env variables, allow-read was required to get the <exec_path>, and unstable was needed because osRelease was used somewhere in the dependency tree (not necessarily this library) instead of Deno.build().

I know this doesn't address the issue at hand, but it does get me around it for the time being and will hopefully help others out.

CoeusCC avatar Jul 24 '21 16:07 CoeusCC

No check avoids the strict TS checks, allow-env is necessary for loading .env variables, allow-read was required to get the <exec_path>, and unstable was needed because osRelease was used somewhere in the dependency tree (not necessarily this library) instead of Deno.build().

@CoeusCC Some of these seem to be expected for the tutorial, but could open issues for the others with a simple example to reproduce?

christophgysin avatar Jul 24 '21 18:07 christophgysin

Similar error here when trying to use RDSDataClient with Deno AWS Lambda:

error: Uncaught SyntaxError: The requested module '../models/models_0.ts' does not provide an export named 'Credentials'
Credentials,
~~~~~~~~~~~
at <anonymous> (<https://deno.land/x/[email protected]/client-sts/protocols/Aws_query.ts>:23:1)

fomalhaut79 avatar Aug 04 '21 15:08 fomalhaut79

Similar error when using client-kms (https://deno.land/x/[email protected]/client-kms/mod.ts)

error: Uncaught SyntaxError: The requested module '../types/mod.ts' does not provide an export named 'Credentials'
import { Credentials, Provider } from "../types/mod.ts";
         ~~~~~~~~~~~
    at <anonymous> (https://deno.land/x/[email protected]/client-sts/defaultStsRoleAssumers.ts:3:10)

sjmueller avatar Sep 22 '21 21:09 sjmueller

I tried all different versions (v3.22.0-1, 3.21.0-1, 3.20.0-1, 3.19.0-1) and all of them failed with the same error. Perhaps something has changed in deno itself that is now causing problems? I'm on:

deno --version
deno 1.14.0 (release, aarch64-apple-darwin)

sjmueller avatar Sep 22 '21 21:09 sjmueller

Greetings! We’re closing this issue because it has been open a long time and hasn’t been updated in a while and may not be getting the attention it deserves. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to comment or open a new issue.

github-actions[bot] avatar Aug 31 '23 00:08 github-actions[bot]