-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrenameFile.js
More file actions
41 lines (36 loc) · 1.22 KB
/
renameFile.js
File metadata and controls
41 lines (36 loc) · 1.22 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
//dependencies
const aws = require('aws-sdk');
const s3 = new aws.S3();
const renameFile = require('./renameFileScript');
//define S3 bucket name and file name
//TODO- define filename from url parameter when adapted for API
const BUCKET = "eddie-tutorial";
const FILENAME = "test.txt";
exports.handler = async function (event, context, callback) {
//Copy file
await s3.copyObject({
CopySource: `${BUCKET}/${FILENAME}`,
Bucket: BUCKET,
Key: renameFile.handler(FILENAME)
}, function(err, data){
if (err) {
console.log(`Error: ${err}`);
} else {
console.log(`Successful Copy`);
}
}
);
//Delete old file
s3.deleteObject({
Bucket: BUCKET,
Key: FILENAME
}, function(err, data) {
if (err) {
console.log(`Error: ${err}`);
} else {
console.log(`Successful Deletion`);
}
}
);
callback(null, `Finished!`);
};