-
Notifications
You must be signed in to change notification settings - Fork 276
/
Copy pathallow-alexa-skill-trigger.js
58 lines (57 loc) · 1.54 KB
/
allow-alexa-skill-trigger.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 loadConfig = require('../util/loadconfig'),
aws = require('aws-sdk');
module.exports = function allowAlexaSkillTrigger(options) {
'use strict';
let lambdaConfig,
lambda;
const initServices = function () {
lambda = new aws.Lambda({region: lambdaConfig.region});
},
getLambda = () => lambda.getFunctionConfiguration({FunctionName: lambdaConfig.name, Qualifier: options.version}).promise(),
readConfig = function () {
return loadConfig(options, {lambda: {name: true, region: true}})
.then(config => {
lambdaConfig = config.lambda;
})
.then(initServices)
.then(getLambda)
.then(result => result.Version);
},
addInvokePermission = function (version) {
return lambda.addPermission({
Action: 'lambda:InvokeFunction',
FunctionName: lambdaConfig.name,
Principal: 'alexa-appkit.amazon.com',
Qualifier: options.version || version,
StatementId: `Alexa-${Date.now()}`
}).promise();
};
return readConfig()
.then(addInvokePermission)
.then(result => JSON.parse(result.Statement));
};
module.exports.doc = {
description: 'Allow Alexa Skill triggers',
priority: 5,
args: [
{
argument: 'version',
optional: true,
description: 'Bind to a particular version',
example: 'production',
default: 'latest version'
},
{
argument: 'source',
optional: true,
description: 'Directory with project files',
default: 'current directory'
},
{
argument: 'config',
optional: true,
description: 'Config file containing the resource names',
default: 'claudia.json'
}
]
};