1 |
|
2 | 'use strict'
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const pify = require('pify')
|
12 | const temp = require('temp').track()
|
13 |
|
14 | const scope = require('../lib/scope.js')
|
15 | const serverless = require('../lib/serverless.js')
|
16 | const logs = require('../lib/logs.js')
|
17 |
|
18 | module.exports = function (
|
19 | input /* : Array<string> */,
|
20 | flags /* : CLIFlags */,
|
21 | logger /* : typeof console */,
|
22 | options /* : CLIOptions */
|
23 | ) /* : Promise<void> */ {
|
24 | return Promise.all([
|
25 | scope.read(flags.cwd),
|
26 | pify(temp.mkdir)('serverless')
|
27 | ])
|
28 | .then((results) => {
|
29 | const cfg = results[0]
|
30 | const tempDir = results[1]
|
31 | return serverless.applyTemplate(tempDir)
|
32 | .then(() => serverless.registerFunctions(tempDir, flags.cwd, flags.env))
|
33 | .then(() => logs.authenticate(cfg, options.blinkMobileIdentity, flags.env))
|
34 | .then((credentials) => {
|
35 | const args = [
|
36 | 'logs',
|
37 | '--function',
|
38 | serverless.getFunctionName(cfg, flags.env),
|
39 | '--region',
|
40 | cfg.region || flags.region,
|
41 | '--stage',
|
42 | flags.env
|
43 | ]
|
44 | if (flags.tail) {
|
45 | args.push('--tail')
|
46 | }
|
47 | if (flags.filter) {
|
48 | args.push('--filter', flags.filter)
|
49 | }
|
50 | if (flags.startTime) {
|
51 | args.push('--startTime', flags.startTime)
|
52 | }
|
53 | const options = {
|
54 | stdio: 'inherit',
|
55 | cwd: tempDir,
|
56 | env: Object.assign({}, process.env, {
|
57 | SLS_IGNORE_WARNING: '*',
|
58 | AWS_ACCESS_KEY_ID: credentials.accessKeyId,
|
59 | AWS_SECRET_ACCESS_KEY: credentials.secretAccessKey,
|
60 | AWS_SESSION_TOKEN: credentials.sessionToken
|
61 | })
|
62 | }
|
63 | return serverless.executeSLSCommand(args, options)
|
64 | .catch(() => Promise.reject(new Error('See Serverless Error above for more details.')))
|
65 | })
|
66 | })
|
67 | }
|