2 Answers
- Newest
- Most votes
- Most comments
4
Here you are using the DocumentClient
which accepts native JSON data:
const dynamoDB = DynamoDBDocumentClient.from(dynamoDBClient)
If you want to continue using DynamoDB JSON you can use the low level client which you have also created:
// remove this client creation // const dynamoDB = DynamoDBDocumentClient.from(dynamoDBClient) // change the client to use the low level client you have created: dynamoDBClient const result = await dynamoDBClient.send(new UpdateCommand({ TableName: 'chat_messages_tbl', Key: { user_id: { S: 'user123' }, created_at: { N: '1681218896790' } }, UpdateExpression: 'SET bot_answer = :bot_answer', ExpressionAttributeValues: { ':bot_answer': { S: 'Hello from bot!' } }, ReturnValues: 'UPDATED_NEW' }))
Or if you want to use native JSON do the following:
const dynamoDB = DynamoDBDocumentClient.from(dynamoDBClient) const result = await dynamoDB.send(new UpdateCommand({ TableName: 'chat_messages_tbl', Key: { user_id: 'user123' , created_at: '1681218896790' }, UpdateExpression: 'SET bot_answer = :bot_answer', ExpressionAttributeValues: { ':bot_answer': 'Hello from bot!' }, ReturnValues: 'UPDATED_NEW' }))
If you want more information on the differences on clients, check out this blog post: https://aws.amazon.com/blogs/database/exploring-amazon-dynamodb-sdk-clients/
3
Looks like you must pass native JS types:
Key: {
user_id: 'user123', // No need to wrap in { S: '...' }
created_at: 1681218896790 // No need to wrap in { N: '...' }
},
Also, there is a lib to convert json to dynamodb types and back:
import {unmarshall, marshall} from '@aws-sdk/util-dynamodb'
answered a month ago
Relevant content
- Accepted Answerasked 3 months ago
- AWS OFFICIALUpdated 25 days ago
- AWS OFFICIALUpdated 4 months ago
- AWS OFFICIALUpdated 2 years ago