Closed
Description
Describe the bug
I have a Netlify Function that connect to DynamoDB and everything works well in development, but when I deploy it, the following error occurs during the build.
I'm not using React Native, it´s only a serverless function, but when DynamoDBClient
is required, that error occurs.
Your environment
SDK version number
@aws-sdk/[email protected]
Is the issue in the browser/Node.js/ReactNative?
Node.js
Details of the browser/Node.js/ReactNative version
v12.18.0
Steps to reproduce
You can follow the documentation to create a Netlify function.
This is my code.
require('dotenv').config()
const { DynamoDBClient } = require('@aws-sdk/client-dynamodb')
const { DynamoDBDocument } = require('@aws-sdk/lib-dynamodb')
const dbclient = new DynamoDBClient({
region: process.env.MY_AWS_REGION,
credentials: {
accessKeyId: process.env.MY_AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.MY_AWS_SECRET_ACCESS_KEY
}
})
const ddbDocClient = DynamoDBDocument.from(dbclient)
exports.handler = async () => {
const params = {
TableName: 'todos',
KeyConditionExpression: 'pk = :userid and begins_with(sk, :todokey)',
ExpressionAttributeValues: {
':userid': 'user#1',
':todokey': 'todo#'
}
}
try {
const response = await ddbDocClient.query(params)
const items = response.Items.map(({ sk, data }) => ({
_id: sk.replace('todo#', ''),
...data
}))
return {
statusCode: 200,
body: JSON.stringify(items)
}
} catch (error) {
return {
statusCode: 400,
body: JSON.stringify(error)
}
}
}