Skip to content

HelloWorldStreamFunction in examples fails with sam #1369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scottgerring opened this issue Aug 16, 2023 · 3 comments · Fixed by #1532
Closed

HelloWorldStreamFunction in examples fails with sam #1369

scottgerring opened this issue Aug 16, 2023 · 3 comments · Fixed by #1532
Assignees
Labels
bug Something isn't working priority:3 Neutral - not a core feature or affects less than 40% of users

Comments

@scottgerring
Copy link
Contributor

scottgerring commented Aug 16, 2023

Running sam local invoke on any of the examples in powertools-examples-core and invoking the streaming variant results in an error:

> sam local invoke HelloWorldStreamFunction
.....
Error: Expecting value: line 1 column 1 (char 0)
Traceback:
  File "/usr/local/Cellar/aws-sam-cli/1.95.0/libexec/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)

The issue seems to be that the streaming handler doesn't return a result at all. We should fix this, as it's a rabbit hole users may get stuck in, thinking their is something wrong with their code.

The issue seems to be this one: aws/aws-sam-cli#4656

Expected Behavior

Examples deploy and can be invoked locally with SAM without error.

Current Behavior

HelloWorldStreamFunction example doesn't return a value, and SAM errors out for a local invoke.

Possible Solution

Make the HelloWorldStreamFunction example code return a value.

Environment

  • Powertools for AWS Lambda (Java) version used: 1.16.1
  • Packaging format (Layers, Maven/Gradle): N/A
  • AWS Lambda function runtime: HelloWorldStreamFunction
@scottgerring scottgerring added bug Something isn't working triage priority:3 Neutral - not a core feature or affects less than 40% of users labels Aug 16, 2023
@scottgerring scottgerring moved this from Backlog to Working on it in Powertools for AWS Lambda (Java) Sep 28, 2023
@jasoniharris
Copy link
Contributor

@scottgerring Please assign to me. Had a chat with Michele.

@scottgerring scottgerring assigned jasoniharris and unassigned mriccia Nov 17, 2023
@AlexeySoshin
Copy link
Contributor

@scottgerring
I'm wondering what are we demonstrating with the StreamingAPI example?
If we want to demonstrate response streaming, then we shouldn't invoke it through API Gateway at all, as it doesn't support streaming:
https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/

We could expose this as Lambda URL, though, if this is the goal.

@scottgerring
Copy link
Contributor Author

@scottgerring I'm wondering what are we demonstrating with the StreamingAPI example? If we want to demonstrate response streaming, then we shouldn't invoke it through API Gateway at all, as it doesn't support streaming: https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/

We could expose this as Lambda URL, though, if this is the goal.

the stream handlers are streaming in the java sense, not the HTTP sense - they're just there so you can read and write back from the request and response directly without any intermediate serialization happening for you. There's some doco on it here.

From our perspective it's valuable to show that you can use PT with this sort of request handler too. In the example we have:

public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
Map map = mapper.readValue(input, Map.class);
System.out.println(map.size());
}
}

If you read between the lines a bit, you could imagine that the user needs to do custom serialization on the response, so they have to use a stream handler. On the request side, they just want to deserialize things normally, so they use ObjectMapper for that. But we don't write any response! Maybe we could return something that makes it make more sense? 🤷

@jasoniharris jasoniharris linked a pull request Nov 28, 2023 that will close this issue
6 tasks
@jeromevdl jeromevdl moved this from Working on it to Shipped in Powertools for AWS Lambda (Java) Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority:3 Neutral - not a core feature or affects less than 40% of users
Projects
Status: Shipped
Development

Successfully merging a pull request may close this issue.

4 participants