aws-sdk-js-v3
aws-sdk-js-v3 copied to clipboard
Error when importing `client-dynamodb` module in AWS Lambda
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
- Deno 1.9.0 and a Deno AWS Lambda handler for 1.9.0 found here.
- [email protected]
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} 🦕`,
};
}
Sorry for the late reply. Can you reproduce that with the latest version?
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)
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)
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.
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.
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.
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?
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)
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)
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)
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.