-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathindex.js
More file actions
62 lines (53 loc) · 2.11 KB
/
index.js
File metadata and controls
62 lines (53 loc) · 2.11 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
50
51
52
53
54
55
56
57
58
59
60
61
62
import Promise from 'bluebird'
import buildFuncs from '../util/build-functions'
import upload from '../util/upload-functions'
import uploadBuilds from '../util/upload-builds'
import { deploy } from '../util/aws/api-gateway'
import setPermissions from '../util/set-permissions'
import * as load from '../util/load'
import push from '../util/push-api'
export default async function ({ apiId, api: deployApi = true, functions = '*', env = 'development', region, bucket, build = true, logger = () => {}, quiet }) {
const api = await load.api()
let uploadFuncs, aliases
try {
if (build) {
logger({ type: 'start', body: `Build Functions` })
await buildFuncs(functions, env, { quiet })
} else {
logger({ type: 'skip', body: 'Called with --no-build' })
}
if (bucket) {
logger({ type: 'start', body: `Upload Builds to S3` })
const funcs = await uploadBuilds(functions, bucket)
uploadFuncs = funcs
} else {
logger({ type: 'skip', body: 'Skipping uploading builds, no S3 bucket provided' })
uploadFuncs = await Promise.map(load.funcs(functions), (name) => { return { name } })
}
logger({ type: 'start', body: 'Upload Functions to AWS' })
aliases = await upload(uploadFuncs, env)
if (deployApi && api) {
logger({ type: 'start', body: 'Upload API.json' })
apiId = await push(api, apiId, region)
} else {
logger({ type: 'skip', body: 'No API' })
}
if (api) {
logger({ type: 'start', body: 'Setup Lambda Permissions' })
await setPermissions(api, apiId, env)
if (deployApi) {
logger({ type: 'start', body: 'Deploy API' })
await deploy(apiId, env)
}
} else {
logger({ type: 'skip', body: 'No API' })
}
} catch (e) {
logger({ type: 'fail' })
throw e
}
logger({ type: 'done' })
aliases.map(({ FunctionName, Identifier }) => `Deployed version ${Identifier.Version} for ${FunctionName}`).forEach((n) => logger(n))
if (apiId) { logger(`API URL: https://${apiId}.execute-api.${region}.amazonaws.com/${env}`) }
return `https://${apiId}.execute-api.${region}.amazonaws.com/${env}`
}