Sls invoke / sls invoke local problems


#1

Hi Folks, new to serverless but been messing about with aws and lambda for long enough to adore the concept.
Installed the framework and have deployed several nodejs examples successfully to aws. (hello / aws-node-simple-http-endpoint etc. ) examples.

However every time i try an ‘sls invoke -f hello’ or ‘sls invoke local -f hello’ it just hangs displaying nothing. I can invoke the functions using the aws cli no problem or trigger errors if i provide an invalid function name, any ideas ?

Note this was done in a cygwin environment on windows, and same behavior seen on home and work environments.

Below is a shell log showing this oddness. Any ideas on where I’ve gone wrong ?

Cheers,
~John

John@Alien-Reborn ~/aws
$ sls create --template=aws-nodejs --path test

WARNING: You are running v1.7.0. v1.8.0 will include the following breaking changes:
- Will replace IamPolicyLambdaExecution resource with inline policies -> #############
- “sls info” will output the short function name rather than the lambda name -> #############

You can opt-out from these warnings by setting the “SLS_IGNORE_WARNING=*” environment variable.

Serverless: Generating boilerplate…
Serverless: Generating boilerplate in “D:\cygwin64\home\John\aws\test”


| _ .-----.----.–.--.-----.----| .-----.-----.-----.
| || -| _| | | -| _| | -|_ --|__ --|
|____ ||| _/||| ||||_____|
| | | The Serverless Application Framework
| | serverless.com, v1.7.0
-------’

Serverless: Successfully generated boilerplate for template: “aws-nodejs”

John@Alien-Reborn ~/aws
$ cd test/

John@Alien-Reborn ~/aws/test
$ pwd
/home/John/aws/test

John@Alien-Reborn ~/aws/test
$ ls -la
total 6
drwxr-xr-x+ 1 John John 0 Feb 25 12:31 .
drwxr-xr-x+ 1 John John 0 Feb 25 12:31 …
-rwxr-xr-x 1 John John 86 Feb 25 12:31 .npmignore
-rwxr-xr-x 1 John John 466 Feb 25 12:31 handler.js
-rwxr-xr-x 1 John John 2607 Feb 25 12:31 serverless.yml

John@Alien-Reborn ~/aws/test
$ cat handler.js
’use strict’;

module.exports.hello = (event, context, callback) => {
const response = {
statusCode: 200,
body: JSON.stringify({
message: ‘Go Serverless v1.0! Your function executed successfully!’,
input: event,
}),
};

callback(null, response);

// Use this code if you don’t use the http event with the LAMBDA-PROXY integration
// callback(null, { message: ‘Go Serverless v1.0! Your function executed successfully!’, event });
};

John@Alien-Reborn ~/aws/test
$ sls deploy

WARNING: You are running v1.7.0. v1.8.0 will include the following breaking changes:
- Will replace IamPolicyLambdaExecution resource with inline policies -> ###############
- “sls info” will output the short function name rather than the lambda name -> ###############

You can opt-out from these warnings by setting the “SLS_IGNORE_WARNING=*” environment variable.

Serverless: Creating Stack…
Serverless: Checking Stack create progress…

Serverless: Stack create finished…
Serverless: Packaging service…
Serverless: Uploading CloudFormation file to S3…
Serverless: Uploading service .zip file to S3 (583 B)…
Serverless: Updating Stack…
Serverless: Checking Stack update progress…

Serverless: Stack update finished…
Service Information
service: test
stage: dev
region: us-east-1
api keys:
None
endpoints:
None
functions:
test-dev-hello

John@Alien-Reborn ~/aws/test
$ sls invoke -f hello

WARNING: You are running v1.7.0. v1.8.0 will include the following breaking changes:
- Will replace IamPolicyLambdaExecution resource with inline policies -> #############
- “sls info” will output the short function name rather than the lambda name -> #############

You can opt-out from these warnings by setting the “SLS_IGNORE_WARNING=*” environment variable.

^C

John@Alien-Reborn ~/aws/test

John@Alien-Reborn ~/aws/test
$ sls invoke local -f hello

WARNING: You are running v1.7.0. v1.8.0 will include the following breaking changes:
- Will replace IamPolicyLambdaExecution resource with inline policies -> ###############
- “sls info” will output the short function name rather than the lambda name -> ###############

You can opt-out from these warnings by setting the “SLS_IGNORE_WARNING=*” environment variable.

^C

John@Alien-Reborn ~/aws/test
$ aws lambda invoke --function test-dev-hello “outfile”
{
“StatusCode”: 200
}

John@Alien-Reborn ~/aws/test
$ cat outfile
{“statusCode”:200,“body”:"{“message”:“Go Serverless v1.0! Your function executed successfully!”,“input”:{}}"}
John@Alien-Reborn ~/aws/test
$


#2

I have the same problem. Followed the Hello World example, it deployed fine, but invoke hangs indefinitely. When I go to AWS and test there, it works fine, telling me the deploy worked fine but the invoke is the failure. Did you find a solution?


#3

Sorry Doug, no solution. I wrote it off to some quirk of running it in a windows cygwin environment and switched to my mac.


#4

Try passing empty data with --data or -d switch. Using your example above

sls invoke local -f hello -d


#5

Following this i had tried -d before with no joy.

Trying --data exposed an error message about lack of aws-sdk in node modules

A quick:

$ npm install aws-sdk

In the serverless project directory seems to have fixed it . Thanks!