-
Notifications
You must be signed in to change notification settings - Fork 2
/
aws.js
46 lines (40 loc) · 1.37 KB
/
aws.js
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
import AWS from 'aws-sdk';
// const { config } = require("./config/index.js");
import config from "./config/index.js";
const SQS = new AWS.SQS({
accessKeyId: config.awsAccessKeyId,
secretAccessKey: config.awsSecretKey,
region: AWS_REGION,
});
export default {
SQS,
helper: {
getEncodingJob: video => {
return {
permlink: video.permlink,
filename: video.filename,
thumbnail: video.thumbnail
}
},
sendMessage: async (queue, message) => {
const parameter = {
MessageBody: typeof message === 'string' ? message : JSON.stringify(message),
QueueUrl: (await SQS.getQueueUrl({QueueName: queue}).promise()).QueueUrl,
};
return SQS.sendMessage(parameter).promise()
},
receiveMessage: async (queue) => {
const parameter = {
QueueUrl: (await SQS.getQueueUrl({QueueName: queue}).promise()).QueueUrl
}
return SQS.receiveMessage(parameter).promise()
},
deleteMessage: async (queue, ReceiptHandle) => {
const parameter = {
QueueUrl: (await SQS.getQueueUrl({QueueName: queue}).promise()).QueueUrl,
ReceiptHandle
}
return SQS.deleteMessage(parameter).promise()
}
}
};