Skip to content

Commit

Permalink
fix: fix processing lambda container response if nothing returned (#5771
Browse files Browse the repository at this point in the history
)

* fix: fix processing lambda container response if nothing returned

* add integration test case
  • Loading branch information
moelasmar authored Aug 16, 2023
1 parent bed8fe2 commit ca6e4e8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion samcli/local/docker/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def wait_for_http_response(self, name, event, stdout) -> str:
data=event.encode("utf-8"),
timeout=(self.RAPID_CONNECTION_TIMEOUT, None),
)
return json.dumps(json.loads(resp.content), ensure_ascii=False)
return json.dumps(json.loads(resp.content), ensure_ascii=False) if resp.content else ""

def wait_for_result(self, full_path, event, stdout, stderr, start_timer=None):
# NOTE(sriram-mv): Let logging happen in its own thread, so that a http request can be sent.
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/local/invoke/test_integrations_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ def test_invoke_returncode_is_zero(self):

self.assertEqual(process.returncode, 0)

@pytest.mark.flaky(reruns=3)
def test_invoke_no_response_returncode_is_zero(self):
command_list = InvokeIntegBase.get_command_list(
"NoResponseServerlessFunction", template_path=self.template_path, event_path=self.event_path
)

process = Popen(command_list, stdout=PIPE)
try:
process.communicate(timeout=TIMEOUT)
except TimeoutExpired:
process.kill()
raise

self.assertEqual(process.returncode, 0)

# https://github.com/aws/aws-sam-cli/issues/2494
@pytest.mark.flaky(reruns=3)
def test_invoke_with_utf8_event(self):
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/testdata/invoke/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ def execute_git(event, context):
assert return_code == 0

return "git init passed"


def no_response(event, context):
print("lambda called")
8 changes: 8 additions & 0 deletions tests/integration/testdata/invoke/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ Resources:
CodeUri: .
Timeout: 600

NoResponseServerlessFunction:
Type: AWS::Serverless::Function
Properties:
Handler: main.no_response
Runtime: python3.9
CodeUri: .
Timeout: 600

HelloWorldLambdaFunction:
Type: AWS::Lambda::Function
Properties:
Expand Down

0 comments on commit ca6e4e8

Please sign in to comment.