I have a Gen 2 Amplify function that is working in sandbox but failing when deploying.
My handler.ts starts with ......
import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb"; import { ApiGatewayManagementApiClient, PostToConnectionCommand, } from "@aws-sdk/client-apigatewaymanagementapi"; import { CognitoJwtVerifier } from "aws-jwt-verify";
and have package.json
{ "name": "collaborationhandler", "type": "module", "dependencies": { "@aws-sdk/client-apigatewaymanagementapi": "^3.726.1", "@aws-sdk/client-dynamodb": "^3.726.1", "@aws-sdk/lib-dynamodb": "^3.726.1", "aws-jwt-verify": "^5.0.0" } }
This works in the Sandbox but fails in deploy with the following errors having added --debug to the build step.
[DEBUG] 2025-01-16T05:01:33.344Z: ✘ [ERROR] Could not resolve "@aws-sdk/client-dynamodb" amplify/functions/collaborationHandler/handler.ts:1:31: 1 │ import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~ You can mark the path "@aws-sdk/client-dynamodb" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
And similar messages for the other imports.
I added exclude "amplify.." in my amplify/tsconfig from this https://docs.amplify.aws/react/build-a-backend/troubleshooting/cannot-find-module-amplify-env/ but that didn't help.
I'd really appreciate any help and apologies if I made any mistakes, this is my first time posting here.