-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
58 lines (47 loc) · 1.95 KB
/
index.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
47
48
49
50
51
52
53
54
55
56
57
58
const {
makeCreateOrUpdateSNSDestination,
makeRemoveSNSDestination,
makeCreateTopic,
makeRemoveTopic
} = require('./src/aws');
const { makeCreateSNSDestinationHook, makeRemoveSNSDestinationHook } = require('./src/plugin');
const getClients = (serverless) => {
const provider = serverless.getProvider('aws');
const awsCredentials = provider.getCredentials();
const region = serverless.service.custom.snsDestination.region || awsCredentials.region;
const credentials = awsCredentials.credentials;
return {
ses: new provider.sdk.SES({ region, credentials }),
sns: new provider.sdk.SNS({ region, credentials })
}
}
const makeCreateHook = (serverless) => {
const { ses, sns } = getClients(serverless);
const createTopic = makeCreateTopic(sns);
const createOrUpdateSNSDestination = makeCreateOrUpdateSNSDestination(ses);
return makeCreateSNSDestinationHook(createTopic, createOrUpdateSNSDestination, serverless.cli);
};
const makeRemoveHook = (serverless) => {
const { ses, sns } = getClients(serverless);
const removeTopic = makeRemoveTopic(sns);
const removeSNSDestination = makeRemoveSNSDestination(ses);
return makeRemoveSNSDestinationHook(removeTopic, removeSNSDestination, serverless.cli);
}
class ServerlessSESConfigurationSetSNSDestination {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;
if (!serverless.service.custom.snsDestination) {
this.serverless.cli.log(`Missing configuration for plugin serverless-ses-sns`);
} else {
this.hooks = this.setupHooks();
}
}
setupHooks() {
return {
'after:deploy:deploy': () => makeCreateHook(this.serverless)(this.serverless.service),
'before:remove:remove': () => makeRemoveHook(this.serverless)(this.serverless.service)
};
}
}
module.exports = ServerlessSESConfigurationSetSNSDestination;