-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynoDB.js
More file actions
54 lines (41 loc) · 1.1 KB
/
Copy pathdynoDB.js
File metadata and controls
54 lines (41 loc) · 1.1 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require('dotenv').config()
const Dynamodb = require('aws-sdk/clients/dynamodb')
const tableName = process.env.AWS_DYNAMODB_TABLE
const region = process.env.AWS_BUCKET_REGION
const dynamodb = new Dynamodb({
region
})
// It creates a new item in dynamodb and return newItem object
async function createNewItem(S3Keys,shortURL){
const newItem = {
S3key:{S:String(S3Keys)},
shortURL:{S:shortURL}
}
const params = {
TableName : tableName,
Item : newItem
}
dynamodb.putItem(params, function (err, data){
if(err){
console.log("ERR");
console.log(err);
}
else{
}
})
return newItem
}
exports.createNewItem = createNewItem
// It gets the short url and try to get item from dynamodb Database and return object
async function getS3Key(shortURLKey){
const params = {
TableName : tableName,
Key: {
"shortURL": {
S:shortURLKey
}
}
}
return await dynamodb.getItem(params).promise()
}
exports.getS3Key = getS3Key