aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.5k stars 1.17k forks source link

Bug: Sam local invoke fails when no response RE-RAISING for v 1.98.0 #6088

Open leeonieep opened 11 months ago

leeonieep commented 11 months ago

Description:

Re-raising this issue Bug: Sam local invoke fails when no response #5766 https://github.com/aws/aws-sam-cli/issues/5766 As it is occurring for the latest version of aws-sam-cli v 1.98.0

When calling sam local invoke on a lambda that does not return a response the call fails. This is now only in 1.98, earlier versions work.

Steps to reproduce:

Create a simple lambda that does not return a result.


using Amazon.Lambda.Core;
using Amazon.Lambda.APIGatewayEvents;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace HelloWorld
{
    public class Function
    {
        public void FunctionHandler(APIGatewayProxyRequest apigProxyEvent, ILambdaContext context)
        {
            context.Logger.LogInformation($"Lambda called.");
        }
    }
}

Run sam build and sam local invoke.

Observed result:

Error during call.

2023-08-15 08:41:07,943 | Starting a timer for 10 seconds for function 'HelloWorldFunction'                                                                                                                     
START RequestId: 6c0fd131-4477-471b-bcd0-cfc547a1d637 Version: $LATEST
2023-08-15T07:41:09.923Z        6c0fd131-4477-471b-bcd0-cfc547a1d637    info    Lambda 85.255.26.184
END RequestId: 6c0fd131-4477-471b-bcd0-cfc547a1d637
REPORT RequestId: 6c0fd131-4477-471b-bcd0-cfc547a1d637  Init Duration: 1.08 ms  Duration: 1954.73 ms    Billed Duration: 1955 ms        Memory Size: 256 MB     Max Memory Used: 256 MB 
2023-08-15 08:41:10,147 | Cleaning all decompressed code dirs                                                                                                                                                   
2023-08-15 08:41:10,150 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics                                                                            
2023-08-15 08:41:10,221 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics                                                                            
2023-08-15 08:41:10,222 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '35502cc9-fd2c-4af0-b13f-4602b5b04fd4', 'installationId': 'ecbf76d5-11f9-4275-91fe-44e2b561ee8d', 'sessionId':           
'2e96b153-2b3d-43a3-9e97-33a3cafcd5ef', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.13', 'samcliVersion': '1.98.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '',     
'commandName': 'sam local invoke', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName': '872e4e50ce9990d8b041330c47c9ddd11bec6b503ae9386a99da8584e9bb12c4', 'initialCommit':    
None}, 'duration': 9389, 'exitReason': 'JSONDecodeError', 'exitCode': 255}}]}                                                                                                                                   
2023-08-15 08:41:10,222 | Unable to find Click Context for getting session_id.                                                                                                                                  
2023-08-15 08:41:10,226 | Sending Telemetry: {'metrics': [{'events': {'requestId': 'ef557975-0439-46f9-88fa-c9c831af6dee', 'installationId': 'ecbf76d5-11f9-4275-91fe-44e2b561ee8d', 'sessionId':               
'2e96b153-2b3d-43a3-9e97-33a3cafcd5ef', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.13', 'samcliVersion': '1.98.0', 'metricSpecificAttributes': {'events': [{'event_name':                    
'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '69fa9474da574059b08ce269cdbb82d0', 'time_stamp': '2023-08-15 07:41:00.738', 'exception_name': None}]}}}]}                                       
2023-08-15 08:41:10,690 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)                                                      
2023-08-15 08:41:10,692 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)                                                      

Error: Expecting value: line 1 column 1 (char 0)
Traceback:
  File "click/core.py", line 1055, in main
  File "click/core.py", line 1657, in invoke
  File "click/core.py", line 1657, in invoke
  File "click/core.py", line 1404, in invoke
  File "click/core.py", line 760, in invoke
  File "click/decorators.py", line 84, in new_func
  File "click/core.py", line 760, in invoke
  File "samcli/lib/telemetry/metric.py", line 184, in wrapped
  File "samcli/lib/telemetry/metric.py", line 149, in wrapped
  File "samcli/lib/utils/version_checker.py", line 42, in wrapped
  File "samcli/cli/main.py", line 95, in wrapper
  File "samcli/commands/local/invoke/cli.py", line 100, in cli
  File "samcli/commands/local/invoke/cli.py", line 206, in do_cli
  File "samcli/commands/local/lib/local_lambda.py", line 144, in invoke
  File "samcli/lib/telemetry/metric.py", line 324, in wrapped_func
  File "samcli/local/lambdafn/runtime.py", line 201, in invoke
  File "samcli/local/docker/container.py", line 354, in wait_for_result
  File "samcli/lib/utils/retry.py", line 30, in wrapper
  File "samcli/local/docker/container.py", line 334, in wait_for_http_response
  File "json/__init__.py", line 357, in loads
  File "json/decoder.py", line 337, in decode
  File "json/decoder.py", line 355, in raw_decode

An unexpected error was encountered while executing "sam local invoke".

Expected result:

Calling the lambda completes successfully and no error occurs.

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

{
  "version": "1.98.0",
  "system": {
    "python": "3.8.17",
    "os": "macOS-14.0-arm64-arm-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "24.0.6",
    "aws_cdk": "Not available",
    "terraform": "Not available"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}

Add --debug flag to command you are running

mndeveci commented 11 months ago

Hi there,

I've tested this scenario on Linux & Windows machines and I was able to successfully invoke the function (I've set the runtime to dotnet6 btw). I will re-try with M1 Mac and see if I can re-produce this issue.

mndeveci commented 11 months ago

Hi there,

We've tried on M1 Mac but we weren't able to re-produce this problem. But, looking at another issue (https://github.com/aws/aws-sam-cli/issues/6102), it seems like Docker might not be able to complete its latest update successfully. So I would recommend doing a clean/re-install of the docker and re-try from scratch.