forked from oslabs-beta/Airfn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeployController.js
More file actions
49 lines (49 loc) · 1.53 KB
/
deployController.js
File metadata and controls
49 lines (49 loc) · 1.53 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
42
43
44
45
46
47
48
49
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const YAML_CONFIG_TEMPLATE = {
AWSTemplateFormatVersion: '2010-09-09',
Transform: 'AWS::Serverless-2016-10-31',
Description: 'Deployed with Lambda 9 CLI.',
Resources: {},
};
exports.default = (join, fs, safeDump) => {
const funcArr = [];
const yamlConfig = YAML_CONFIG_TEMPLATE;
fs.readdirSync(join(process.cwd(), `/functions`)).forEach((file) => {
createFunctionResource(file, yamlConfig);
const data = fs.readFileSync(join(process.cwd(), `/functions/${file}`), 'utf8');
const funcObj = {
funcName: file,
funcDef: data,
};
funcArr.push(funcObj);
});
return {
yamlConfig: safeDump(yamlConfig),
funcArr,
};
};
function createFunctionResource(fileName, yamlConfig) {
fileName = fileName.replace(/\.[^/.]+$/, '');
const funcTemplate = {
Type: 'AWS::Serverless::Function',
Properties: {
Handler: `${fileName}.handler`,
Runtime: 'nodejs8.10',
CodeUri: '.',
Description: 'A function deployed with Lambda 9 CLI',
MemorySize: 512,
Timeout: 10,
Events: {
Api1: {
Type: 'Api',
Properties: {
Path: `/${fileName}`.toLowerCase(),
Method: 'ANY',
},
},
},
},
};
yamlConfig.Resources[fileName] = funcTemplate;
}