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

Error when importing client-dynamodb module in AWS Lambda #11

Closed
GJZwiers opened this issue Apr 29, 2021 · 11 comments
Closed

Error when importing client-dynamodb module in AWS Lambda #11

GJZwiers opened this issue Apr 29, 2021 · 11 comments
Labels
bug Something isn't working closed-for-staleness

Comments

@GJZwiers
Copy link

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 GJZwiers added the bug Something isn't working label Apr 29, 2021
@christophgysin
Copy link
Owner

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

@GJZwiers
Copy link
Author

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)

@CoeusCC
Copy link

CoeusCC commented Jul 24, 2021

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
Copy link

CoeusCC commented Jul 24, 2021

I'm not certain what the issue is, but this seems to be related: nodejs/node#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
Copy link

CoeusCC commented Jul 24, 2021

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
Copy link

CoeusCC commented Jul 24, 2021

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.

@christophgysin
Copy link
Owner

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?

@fomalhaut79
Copy link

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)

@sjmueller
Copy link

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
Copy link

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)

@github-actions
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working closed-for-staleness
Projects
None yet
Development

No branches or pull requests

5 participants