Got Error: Please provide a valid entity definition
Opened this issue ยท 2 comments
yvza commented
Hi everyone, why i got this error, i dont know how to solve this ๐
already googled and digging into issue list but doesnt find related issue
Code :
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'
import { Table, Entity } from 'dynamodb-toolbox'
const awsCredetnials = {
accessKeyId: process.env.NEXT_PUBLIC_AWS_ACCOUNT_ACCESS_KEY,
secretAccessKey: process.env.NEXT_PUBLIC_AWS_ACCOUNT_SECRET_KEY,
}
const dynamoConfig = {
region: process.env.NEXT_PUBLIC_AWS_ACCOUNT_REGION,
credentials: awsCredetnials,
} as {
credentials: {
accessKeyId: string
secretAccessKey: string
}
region: string
}
const DocumentClient = DynamoDBDocumentClient.from(new DynamoDBClient(dynamoConfig), {
marshallOptions: {
convertEmptyValues: true,
removeUndefinedValues: true,
convertClassInstanceToMap: false,
},
})
const table = new Table({
name: 'accesspass',
partitionKey: 'pk',
sortKey: 'sk',
DocumentClient
})
const AccessPass = new Entity({
attributes: {
pk: { partitionKey: true },
sk: { sortKey: true, hidden: true },
identifier: { type: 'string', required: true },
type: { type: 'string', required: true }
},
table,
name: 'AccessPass'
} as const )
const isProd = process.env.NEXT_PUBLIC_NODE_ENV === 'production'
const appUrl = !isProd
? 'http://localhost:3000'
: 'https://[REDACTED]'
export { dynamoConfig, AccessPass, appUrl, isProd }
Env :
"react": "^18",
"next": "14.0.4",
"@aws-sdk/client-dynamodb": "^3.484.0",
"@aws-sdk/lib-dynamodb": "^3.485.0",
"dynamodb-toolbox": "^0.9.5",
its workin, when i access directly using API approach
import { NextApiRequest, NextApiResponse } from "next"
import { AccessPass } from "@/config"
export default async function handler(
request: NextApiRequest,
response: NextApiResponse
) {
if (request.method !== 'GET') return response.status(500).end()
const test = {
pk: 'SOMEKEY',
sk: 'SOMEKEY'
}
const res = await AccessPass.get(test)
return response.status(200).json(res)
}