aws-lambda-dotnet icon indicating copy to clipboard operation
aws-lambda-dotnet copied to clipboard

LambdaTestTool not populating LambdaContext

Open dude0001 opened this issue 4 years ago • 4 comments

Is the mock lambda test tool supposed to populate values in the ILambdaContext in my function handler?

Specifically, in my config file, I have function-timeout set to 30 and function-memory-size set to 512. I am expecting those to be populated in the ILambdaContext that gets passed in as RemainingTime and MemoryLimitInMB respectively, but they are just getting their defaults zero values.

This is problematic in my function as I set up a CancelationTokenSource that reserves a few seconds of RemainingTime to gracefully shutdown. I have to add some special logic to account for the 0 value that tool passes in that I don't really want in my code.

{
  "Information": [
    "This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
    "To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",

    "dotnet lambda help",

    "All the command line options for the Lambda command can be specified in this file."
  ],

  "profile": "default",
  "region": "us-east-2",
  "configuration": "Debug",
  "framework": "netcoreapp3.1",
  "function-runtime": "dotnetcore3.1",
  "function-memory-size": 512,
  "function-timeout": 30,
  "function-handler": "{assembly}::{namespace}.{class}::{method}"
}

image

Edit:

I think I found where the mocked LambdaContext is being created and this is supposed to be happening. Looks like nothing is being set yet though. Seems like it should be pretty easy to implement filing in the mocked LambdaContext from the config file.

https://github.com/aws/aws-lambda-dotnet/blob/85dd6e164c324120535815e02c30e3ae2e5d72f3/Tools/LambdaTestTool/src/Amazon.Lambda.TestTool/Runtime/LambdaExecutor.cs#L41

dude0001 avatar May 07 '20 01:05 dude0001

I've made a start to looking at implementing this (I need/would like the AwsRequestId populated), but I'm not sure how we should handle certain scenarios.

Auto populating certaing properties, like the Request Id and not the other 'always available' properties would be odd.

So passing them all in as a config file seems like a sensible thing to do, but what should we do in scenarios when a user doesn't pass them in in the config? Should we default things like InvokedFunctionArn or the FunctionVersion to something?

@philasmar or @normj Do you know if anything has start looking into this?

ryancormack avatar Oct 02 '20 14:10 ryancormack

This would be a great feature!

patricm-enbw avatar Feb 21 '23 15:02 patricm-enbw

This would be a great feature!

I agree.

tim-hampton avatar Apr 25 '24 16:04 tim-hampton

Will that be implemented? I would also like to see RemainingTime to be populated from aws-lambda-tools-defaults.json

Sonic198 avatar Jul 29 '24 21:07 Sonic198