mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const AWS = require('aws-sdk');
|
|
const { region, persistentRequest } = require('../misc');
|
|
|
|
function createSnsTopic(topicName) {
|
|
const SNS = new AWS.SNS({ region });
|
|
|
|
const params = {
|
|
Name: topicName,
|
|
};
|
|
|
|
return SNS.createTopic(params).promise();
|
|
}
|
|
|
|
function removeSnsTopic(topicName) {
|
|
const SNS = new AWS.SNS({ region });
|
|
|
|
return SNS.listTopics().promise()
|
|
.then(data => {
|
|
const topicArn = data.Topics.find(topic => RegExp(topicName, 'g')
|
|
.test(topic.TopicArn)).TopicArn;
|
|
|
|
const params = {
|
|
TopicArn: topicArn,
|
|
};
|
|
|
|
return SNS.deleteTopic(params).promise();
|
|
});
|
|
}
|
|
|
|
function publishSnsMessage(topicName, message) {
|
|
const SNS = new AWS.SNS({ region });
|
|
|
|
return SNS.listTopics().promise()
|
|
.then(data => {
|
|
const topicArn = data.Topics.find(topic => RegExp(topicName, 'g')
|
|
.test(topic.TopicArn)).TopicArn;
|
|
|
|
const params = {
|
|
Message: message,
|
|
TopicArn: topicArn,
|
|
};
|
|
|
|
return SNS.publish(params).promise();
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
createSnsTopic: persistentRequest.bind(this, createSnsTopic),
|
|
removeSnsTopic: persistentRequest.bind(this, removeSnsTopic),
|
|
publishSnsMessage: persistentRequest.bind(this, publishSnsMessage),
|
|
};
|