Looking at your code I presume you're using Amplify Gen 2 backend?
They've moved from the Gen 1 way of doing this (where amplify generates the table variables etc.). The Lambda should use the schema with generateClient from aws-amplify/data to access the dynamodb tables. This is far better than messing around with env variables everywhere IMO. The schema has to allow the lambda function to do this - permissions defined in the (amplify/data/resource.ts).
Follow the guide here:
https://docs.amplify.aws/react-native/build-a-backend/functions/examples/create-user-profile-record/
You need the latest version of everything amplify. To support importing env from "$amplify/env/post-confirmation" I had to add the path to the amplify/tsconfig.json:
{
"compilerOptions": {
"target": "es2022",
"module": "es2022",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"paths": {
"$amplify/*": ["../.amplify/generated/*"]
}
},
}