Skip to content

getRemainingTimeInMillis is returning a unix time #2519

Description

@danjordan

Description:

Since v1.13.1 context.getRemainingTimeInMillis() is returning an integer that represents a recent date, rather than the remaining time in milliseconds.

This also occurs in Ruby lambdas, however Python 2 lambdas give us 0. All three work correctly in v1.12.0.

Steps to reproduce:

# template.yaml

Transform: AWS::Serverless-2016-10-31

Resources:
  Index:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs12.x
      Timeout: 5
      Events:
        Api:
          Type: Api
          Properties:
            Path: /
            Method: GET
// index.js

exports.handler = async (event, context) => {
  return {
    body: JSON.stringify({
      remainingTimeInMillis: context.getRemainingTimeInMillis(),
      date: new Date(context.getRemainingTimeInMillis()),
    }),
  };
};

Observed result:

Running the following command with v1.13.1
sam local invoke Index --debug

2021-01-06 14:18:28,422 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2021-01-06 14:18:28,510 | local invoke command is called
2021-01-06 14:18:28,513 | No Parameters detected in the template
2021-01-06 14:18:28,534 | 2 resources found in the template
2021-01-06 14:18:28,534 | Found Serverless function with name='Index' and CodeUri='.'
2021-01-06 14:18:28,540 | Found one Lambda function with name 'Index'
2021-01-06 14:18:28,541 | Invoking index.handler (nodejs12.x)
2021-01-06 14:18:28,541 | No environment variables found for function 'Index'
2021-01-06 14:18:28,541 | Environment variables overrides data is standard format
2021-01-06 14:18:28,541 | Loading AWS credentials from session with profile 'None'
2021-01-06 14:18:28,553 | Resolving code path. Cwd=/Users/danjordan/Sites/misc/sam-cli-test, CodeUri=.
2021-01-06 14:18:28,553 | Resolved absolute path to code is /Users/danjordan/Sites/misc/sam-cli-test
2021-01-06 14:18:28,553 | Code /Users/danjordan/Sites/misc/sam-cli-test is not a zip/jar file
2021-01-06 14:18:28,574 | Skip pulling image and use local one: amazon/aws-sam-cli-emulation-image-nodejs12.x:rapid-1.13.1.

2021-01-06 14:18:28,574 | Mounting /Users/danjordan/Sites/misc/sam-cli-test as /var/task:ro,delegated inside runtime container
2021-01-06 14:18:28,901 | Starting a timer for 5 seconds for function 'Index'
START RequestId: 46414975-e270-45d2-9c24-5ae61b25cd30 Version: $LATEST
END RequestId: 46414975-e270-45d2-9c24-5ae61b25cd30
REPORT RequestId: 46414975-e270-45d2-9c24-5ae61b25cd30	Init Duration: 0.15 ms	Duration: 85.89 ms	Billed Duration: 100 ms	Memory Size: 128 MB	Max Memory Used: 128 MB
2021-01-06 14:18:29,186 | Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam local invoke', 'duration': 764, 'exitReason': 'success', 'exitCode': 0, 'requestId': 'c6c57255-762e-42af-a8a5-599eee573190', 'installationId': '190b0744-f13d-4279-84cd-860b54d9c540', 'sessionId': '8a9c4bb4-7609-4a78-9705-ff32bd726835', 'executionEnvironment': 'CLI', 'pyversion': '3.8.7', 'samcliVersion': '1.13.1'}}]}
2021-01-06 14:18:29,858 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)

{"body":"{\"remainingTimeInMillis\":1609931569204,\"date\":\"2021-01-06T11:12:49.204Z\"}"}%

Expected result:

Running the following command with v1.12.0
sam local invoke Index --debug

2021-01-06 14:21:14,642 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2021-01-06 14:21:15,249 | local invoke command is called
2021-01-06 14:21:15,252 | No Parameters detected in the template
2021-01-06 14:21:15,281 | 2 resources found in the template
2021-01-06 14:21:15,281 | Found Serverless function with name='Index' and CodeUri='.'
2021-01-06 14:21:15,288 | Found one Lambda function with name 'Index'
2021-01-06 14:21:15,288 | Invoking index.handler (nodejs12.x)
2021-01-06 14:21:15,288 | No environment variables found for function 'Index'
2021-01-06 14:21:15,288 | Environment variables overrides data is standard format
2021-01-06 14:21:15,288 | Loading AWS credentials from session with profile 'None'
2021-01-06 14:21:15,299 | Resolving code path. Cwd=/Users/danjordan/Sites/misc/sam-cli-test, CodeUri=.
2021-01-06 14:21:15,299 | Resolved absolute path to code is /Users/danjordan/Sites/misc/sam-cli-test
2021-01-06 14:21:15,299 | Code /Users/danjordan/Sites/misc/sam-cli-test is not a zip/jar file
2021-01-06 14:21:15,309 | Skip pulling image and use local one: amazon/aws-sam-cli-emulation-image-nodejs12.x:rapid-1.12.0.

2021-01-06 14:21:15,309 | Mounting /Users/danjordan/Sites/misc/sam-cli-test as /var/task:ro,delegated inside runtime container
2021-01-06 14:21:15,672 | Starting a timer for 5 seconds for function 'Index'
START RequestId: 033cd921-a9e4-1351-c5a5-aae6c40794ae Version: $LATEST
END RequestId: 033cd921-a9e4-1351-c5a5-aae6c40794ae
REPORT RequestId: 033cd921-a9e4-1351-c5a5-aae6c40794ae	Init Duration: 151.36 ms	Duration: 3.38 ms	Billed Duration: 100 ms	Memory Size: 128 MB	Max Memory Used: 41 MB
2021-01-06 14:21:15,934 | Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam local invoke', 'duration': 1290, 'exitReason': 'success', 'exitCode': 0, 'requestId': '2949a164-fb1e-4eeb-a11c-a8ef3d8c09dc', 'installationId': '190b0744-f13d-4279-84cd-860b54d9c540', 'sessionId': '4ccaf64c-8096-4db9-b4fb-b28c728927e5', 'executionEnvironment': 'CLI', 'pyversion': '3.8.7', 'samcliVersion': '1.12.0'}}]}
2021-01-06 14:21:16,624 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)

{"body":"{\"remainingTimeInMillis\":4882,\"date\":\"1970-01-01T00:00:04.882Z\"}"}

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Mac OS Big Sur
  2. sam --version: discovered in v1.15.0, but narrowed down to being introduced in v1.13.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions