Skip to content

Instantly share code, notes, and snippets.

@kiewic
Last active January 11, 2021 21:57
Show Gist options
  • Save kiewic/b175e6a926d3ddd7277463980e8bd3b2 to your computer and use it in GitHub Desktop.
Save kiewic/b175e6a926d3ddd7277463980e8bd3b2 to your computer and use it in GitHub Desktop.
How to insert or delete items from a DynamoDB table using Node.js
var AWS = require('aws-sdk');
var region = "us-west-2";
var accessKeyId = process.env.DYNAMODB_ACCESS_KEY_ID;
var secretAccessKey = process.env.DYNAMODB_SECRET_ACCESS_KEY;
var tableName = "your table name";
var dynamoDB = new AWS.DynamoDB({
region: region,
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
});
// One item with two properties: question_id and title.
var params = {
Item: {
question_id: {
N: "12345" // Number value.
},
title: {
S: "Foo foo foo" // String value.
}
},
ReturnConsumedCapacity: "TOTAL",
TableName: tableName,
};
dynamoDB.putItem(params, function(err, data) {
if (err) {
console.log(err, err.stack);
}
else {
console.log(data);
}
});
var fileItem = {
Key: {
question_id: {
N: "1234" // My partition key is a number.
}
},
TableName: tableName,
};
dynamoDB.deleteItem(fileItem, function(err, data) {
if (err) {
console.log(err, err.stack);
}
else {
console.log(data);
}
});
@steelx
Copy link

steelx commented Sep 22, 2020

deleteItem is not a function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment