Created
August 16, 2019 19:29
Delete v2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const aws = require('aws-sdk'); | |
const dynamoDbClient = new aws.DynamoDB.DocumentClient(); | |
module.exports.delete = async event => { | |
const params = { | |
TableName: process.env.TABLE_NAME, | |
Key: { | |
'id': event.pathParameters.id | |
}, | |
ConditionExpression: 'id = :id', | |
ExpressionAttributeValues: { | |
':id': event.pathParameters.id | |
} | |
}; | |
return new Promise((resolve, reject) => { | |
dynamoDbClient.delete(params, function (err, data) { | |
if (err) { | |
console.log(err); | |
if (err.code == 'ConditionalCheckFailedException') { | |
const response = { | |
statusCode: 404 | |
}; | |
resolve(response); | |
} | |
else { | |
reject(err); | |
} | |
} | |
else { | |
const response = { | |
statusCode: 200, | |
body: null | |
}; | |
resolve(response); | |
} | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment