-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamoDb_update.js
More file actions
30 lines (29 loc) · 837 Bytes
/
dynamoDb_update.js
File metadata and controls
30 lines (29 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
exports.updateItem = async (event) => {
const requestBody = JSON.parse(event.body);
const params = {
TableName: 'YourTableName',
Key: {
id: event.pathParameters.id
},
UpdateExpression: 'set #data = :data',
ExpressionAttributeNames: {
'#data': 'data'
},
ExpressionAttributeValues: {
':data': requestBody.data
},
ReturnValues: 'UPDATED_NEW'
};
try {
const data = await dynamoDb.update(params).promise();
return {
statusCode: 200,
body: JSON.stringify({ message: 'Item updated successfully', data: data.Attributes })
};
} catch (error) {
return {
statusCode: 500,
body: JSON.stringify({ error: error.message })
};
}
};