UNPKG

1.96 kBJavaScriptView Raw
1/* @flow */
2'use strict'
3
4/* ::
5import type {
6 CLIFlags,
7 CLIOptions
8} from '../types.js'
9*/
10
11const pify = require('pify')
12const temp = require('temp').track()
13
14const scope = require('../lib/scope.js')
15const serverless = require('../lib/serverless.js')
16const logs = require('../lib/logs.js')
17
18module.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}