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

Can not use v3 of aws-sdk in lambda for manually created tables #2959

Closed
3 tasks done
mtliendo opened this issue Oct 11, 2024 · 2 comments
Closed
3 tasks done

Can not use v3 of aws-sdk in lambda for manually created tables #2959

mtliendo opened this issue Oct 11, 2024 · 2 comments
Assignees
Labels

Comments

@mtliendo
Copy link

Before opening, please confirm:

JavaScript Framework

Not applicable

Amplify APIs

Not applicable

Amplify Version

v6

Amplify Categories

storage, function, api

Backend

Amplify Gen 2 (Preview)

Environment information

# Put output below this line
System:
    OS: macOS 14.4
    CPU: (14) arm64 Apple M3 Max
    Memory: 544.14 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.9.0 - ~/.nvm/versions/node/v22.9.0/bin/node
    npm: 10.8.3 - ~/.nvm/versions/node/v22.9.0/bin/npm
  Browsers:
    Safari: 17.4
  npmPackages:
    %name%:  0.1.0 
    @aws-amplify/backend: ^1.4.0 => 1.4.0 
    @aws-amplify/backend-cli: ^1.2.9 => 1.2.9 
    @aws-amplify/ui-react: ^6.5.3 => 6.5.3 
    @aws-amplify/ui-react-internal:  undefined ()
    @aws-amplify/ui-react-server:  undefined ()
    @aws-sdk/client-dynamodb: ^3.669.0 => 3.669.0 
    @aws-sdk/lib-dynamodb: ^3.669.0 => 3.669.0 
    @eslint/js: ^9.11.1 => 9.12.0 
    @radix-ui/react-icons: ^1.3.0 => 1.3.0 
    @radix-ui/react-slot: ^1.1.0 => 1.1.0 (1.0.0)
    @types/node: ^22.7.5 => 22.7.5 (20.16.11)
    @types/react: ^18.3.10 => 18.3.11 
    @types/react-dom: ^18.3.0 => 18.3.0 
    @vitejs/plugin-react: ^4.3.2 => 4.3.2 
    autoprefixer: ^10.4.20 => 10.4.20 
    aws-amplify: ^6.6.4 => 6.6.4 
    aws-amplify/adapter-core:  undefined ()
    aws-amplify/analytics:  undefined ()
    aws-amplify/analytics/kinesis:  undefined ()
    aws-amplify/analytics/kinesis-firehose:  undefined ()
    aws-amplify/analytics/personalize:  undefined ()
    aws-amplify/analytics/pinpoint:  undefined ()
    aws-amplify/api:  undefined ()
    aws-amplify/api/server:  undefined ()
    aws-amplify/auth:  undefined ()
    aws-amplify/auth/cognito:  undefined ()
    aws-amplify/auth/cognito/server:  undefined ()
    aws-amplify/auth/enable-oauth-listener:  undefined ()
    aws-amplify/auth/server:  undefined ()
    aws-amplify/data:  undefined ()
    aws-amplify/data/server:  undefined ()
    aws-amplify/datastore:  undefined ()
    aws-amplify/in-app-messaging:  undefined ()
    aws-amplify/in-app-messaging/pinpoint:  undefined ()
    aws-amplify/push-notifications:  undefined ()
    aws-amplify/push-notifications/pinpoint:  undefined ()
    aws-amplify/storage:  undefined ()
    aws-amplify/storage/s3:  undefined ()
    aws-amplify/storage/s3/server:  undefined ()
    aws-amplify/storage/server:  undefined ()
    aws-amplify/utils:  undefined ()
    aws-cdk: ^2.161.1 => 2.161.1 
    aws-cdk-lib: ^2.161.1 => 2.161.1 
    aws-sdk: ^2.1691.0 => 2.1691.0 
    class-variance-authority: ^0.7.0 => 0.7.0 
    clsx: ^2.1.1 => 2.1.1 (2.0.0)
    constructs: ^10.3.1 => 10.3.1 
    esbuild: ^0.24.0 => 0.24.0 (0.23.1, 0.21.5)
    eslint: ^9.11.1 => 9.12.0 
    eslint-plugin-react-hooks: ^5.1.0-rc.0 => 5.1.0-rc-fb9a90fa48-20240614 
    eslint-plugin-react-refresh: ^0.4.12 => 0.4.12 
    globals: ^15.9.0 => 15.10.0 (11.12.0, 14.0.0)
    lucide-react: ^0.451.0 => 0.451.0 
    postcss: ^8.4.47 => 8.4.47 
    react: ^18.3.1 => 18.3.1 
    react-dom: ^18.3.1 => 18.3.1 
    react-router-dom: ^6.26.2 => 6.26.2 
    tailwind-merge: ^2.5.3 => 2.5.3 
    tailwindcss: ^3.4.13 => 3.4.13 
    tailwindcss-animate: ^1.0.7 => 1.0.7 
    tsx: ^4.19.1 => 4.19.1 
    typescript: ^5.6.3 => 5.6.3 (4.4.4, 4.9.5)
    typescript-eslint: ^8.7.0 => 8.8.1 
    vite: ^5.4.8 => 5.4.8 
  npmGlobalPackages:
    corepack: 0.29.3
    npm: 10.8.3

Describe the bug

i'm creating a rest api based on this guide. The guide only goes as far as setting up API Gateway with a Lambda function (optionally with Cognito), but it does not cover saving data to dynamodb.

Using v3 of the aws-sdk, I am saving to dynamodb using the following imports:

import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
import { DynamoDBDocumentClient, PutCommand } from '@aws-sdk/lib-dynamodb'

From there, I am using the following method to save an item to the table:

	await docClient.send(new PutCommand(params))

While this deploys, I get a cryptic error message:

{
    "errorType": "TypeError",
    "errorMessage": "(0 , Yse.setFeature) is not a function",
    "stack": [
        "TypeError: (0 , Yse.setFeature) is not a function",
        "    at file:///var/task/index.mjs:67:11952",
        "    at file:///var/task/index.mjs:2:24314",
        "    at file:///var/task/index.mjs:67:17774",
        "    at cN.send (file:///var/task/index.mjs:12:9605)",
        "    at e (file:///var/task/index.mjs:67:24350)",
        "    at Runtime.Wye [as handler] (file:///var/task/index.mjs:67:24401)",
        "    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)"
    ]
}

During debugging, I confirmed it has to do with the PutCommand. I refactored my code to use v2 of the aws-sdk and it worked as expected.

Expected behavior

I expect to be able to use v3 of the aws-sdk on a manually created table when inside of a lambda function.

Reproduction steps

  1. npm create amplify@latest
  2. delete amplify/data folder
  3. Setup a REST API according to the guide mentioned above
  4. Setup a Table using the L2 CDK construct
  5. Grant the function the necessary permissions to access the table
  6. In the function code, use v3 of the aws-sdk to try and perform operations against the table.
  7. Refactor function code to use v2 to observe working code.

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@github-actions github-actions bot added pending-triage pending-maintainer-response Issue is pending a response from the Amplify team. labels Oct 11, 2024
@chrisbonifacio chrisbonifacio added bug Something isn't working Gen 2 and removed pending-triage labels Oct 11, 2024
@cwomack cwomack removed the pending-maintainer-response Issue is pending a response from the Amplify team. label Oct 16, 2024
@cwomack cwomack transferred this issue from aws-amplify/amplify-js Oct 16, 2024
@mtliendo
Copy link
Author

Closing as the issue was me mixing commonjs exports with esmodules

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

@chrisbonifacio chrisbonifacio self-assigned this Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants