serverless / serverless/serverless

--context or --contextPath flags give TypeError: a.getRemainingTimeInMillis

Open
#12,201 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
46.9k
Forks
5.7k
Avg merge
10h 7m
Merged PRs (30d)
57

Description

Are you certain it's a bug?
  • Yes, it looks like a bug
Is the issue caused by a plugin?
  • It is not a plugin issue
Are you using the latest v3 release?
  • Yes, I'm using the latest v3 release
Is there an existing issue for this?
  • I have searched existing issues, it hasn't been reported yet
Issue description

What using the --context or --contextPath flags with "serverless invoke local -f" it returns and error
TypeError: a.getRemainingTimeInMillis is not a function
at ....\serverless_sdk\index.js:24:5402
at ....\node_modules\serverless\lib\plugins\aws\invoke-local\index.js:953:30
at new Promise ()
at AwsInvokeLocal.invokeLocalNodeJs (....\node_modules\serverless\lib\plugins\aws\invoke-local\index.js:906:12)

when looking at the github code for node_modules\serverless\lib\plugins\aws\invoke-local\index.js
`let context = {
awsRequestId: uuidv4(),
invokeid: 'id',
logGroupName: this.provider.naming.getLogGroupName(this.options.functionObj.name),
logStreamName: '2015/09/22/[HEAD]13370a84ca4ed8b77c427af260',
functionVersion: 'HEAD',
isDefaultFunctionVersion: true,

    functionName: this.options.functionObj.name,
    memoryLimitInMB: '1024',

    succeed(result) {
      return callback(null, result);
    },
    fail(error) {
      return callback(error);
    },
    done(error, result) {
      return callback(error, result);
    },
    getRemainingTimeInMillis() {
      return Math.max(timeout * 1000 - (new Date().valueOf() - startTime.valueOf()), 0);
    },
  };

  if (customContext) {
    context = customContext;
  }`

It appears that context = customContext; removes the getRemainingTimeInMillis in the above let context statement. Likely this overwrite vs merge removes getRemainingTimeInMillis from being passed into

const maybeThennable = lambda(event, context, callback);

This seems to be a bug that makes both these switches not work. If I run without --context or --contextPath it works fine but I can not pass in context variables.

Service configuration (serverless.yml) content
N/A
Command name and used flags

serverless invoke local -f smsReply --path .\mocks\reply_event.json --context '{"invokedFunctionArn": "arn:aws:lambda:us-east-1:111111111111111:function:sms-status-dev-reply"}'

Command output
TypeError: a.getRemainingTimeInMillis is not a function
    at ....\serverless_sdk\index.js:24:5402
    at ....\node_modules\serverless\lib\plugins\aws\invoke-local\index.js:953:30
    at new Promise (<anonymous>)
    at AwsInvokeLocal.invokeLocalNodeJs (....\node_modules\serverless\lib\plugins\aws\invoke-local\index.js:906:12)
Environment information
Running "serverless" from node_modules                                                                                                                                                                                                                                                  
Framework Core: 3.35.2 (local) 3.35.2 (global)
Plugin: 7.0.3
SDK: 4.4.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/plugins/aws/invoke-local/index.js around the context setup and invocation lines cited in the report. Reproduce the supplied serverless invoke local command with --context, then compare it with invocation without that flag. Done means the context flags no longer produce the reported TypeError and the supplied context remains available to the function.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript, node.js
Domain
backend, cloud
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.