Lambda Test Tool: LambdaAnnotations | Proper use of HttpResults and [FromBody] attribute.
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by reproducing the two examples in the Mock Lambda Test Tool: the GET returning HttpResults.Ok("Ok") and the annotated POST using [FromBody] Request with {"name":"test"}. Compare the UI response handling and request-body binding with the behavior described; done means the response is usable in the tool and the POST reaches the function with the request body populated.
Written by the indexing model from the issue text.
Description
Discussed in https://github.com/aws/aws-lambda-dotnet/discussions/1569
Originally posted by sergio-asenjo August 20, 2023
Hello!
I've been trying to figure out how to properly use HttpResults returning statement in the "Mock Lambda Test Tool".
As a short example, I've tried this:
[LambdaFunction()]
[HttpApi(LambdaHttpMethod.Get, "/")]
public IHttpResult Test(ILambdaContext context)
{
return HttpResults.Ok("Ok");
}
Doing so, and returning any type of HttpResults, from the UI of Mock Lambda Test Tool I'm getting a base64 return in response. As for this case, I'm getting:
"eyJzdGF0dXNDb2RlIjoyMDAsImhlYWRlcnMiOnsiY29udGVudC10eXBlIjoidGV4dC9wbGFpbiJ9LCJDb29raWVzIjpudWxsLCJib2R5IjoiT2siLCJpc0Jhc2U2NEVuY29kZWQiOmZhbHNlfQ=="
Which translate to:
{
"statusCode": 200,
"headers": {
"content-type": "text/plain"
},
"Cookies": null,
"body": "Ok",
"isBase64Encoded": false
}
That's correct overall, but for testing purposes, having to decode the base64 to see what I got it's not what I would want to do recurrently. Is this intended or am I missing something? If I deploy it, through browsers I can get instantly a decoded response.
───
A second thing is that I'm trying to use a [FromBody] attribute to get some data passed in the body, like this:
[LambdaFunction()]
[HttpApi(LambdaHttpMethod.Post, "/")]
public IHttpResult Test([FromBody] Request request, ILambdaContext context)
{
return HttpResults.Ok("Ok");
}
public class Request
{
public string Name { get; set; }
}
If through the UI Mock Lambda Test Tool I try to send { "name": "test" }, I get a ValidationException, so it doesn't even enter the Test Function completely.
This is the response (which is also base64 encoded in the UI).
{
"statusCode": 400,
"headers": {
"Content-Type": "application/json",
"x-amzn-ErrorType": "ValidationException"
},
"cookies": null,
"body": "{\u0022message\u0022: \u00221 validation error(s) detected: Value at \u0027body\u0027 failed to satisfy constraint: Value cannot be null. (Parameter \u0027json\u0027)\u0022}",
"isBase64Encoded": false
}
Am I using this correctly for this case? Before trying annotations, I was using the template that comes with Powertools, there I'd just pass the type (in this case would be Request) and I wouldn't get this error.
For both cases, I'm using the base template Serverless Annotation, and deleted what's inside the main Class, everything else is untouched.
- Dominant language
- C#
- Stars
- 1.7k
- Forks
- 503
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 21
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from aws/aws-lambda-dotnet
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
aws/aws-lambda-dotnet#2571 · 1 comment ·
-
bug module/aspnetcore-support p2 queued
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
aws/aws-lambda-dotnet#1123 · 4 comments · 1 reaction ·
-
feature-request
Difficulty 4/5 3-5 days Newbie friendliness 68/100
aws/aws-lambda-dotnet#2572 · 1 comment ·
-
feature-request needs-triage
Difficulty 4/5 3-5 days Newbie friendliness 48/100
aws/aws-lambda-dotnet#2551 · 1 comment ·
-
feature-request needs-review
Difficulty 5/5 Over a week Newbie friendliness 35/100
aws/aws-lambda-dotnet#2519 ·
All issues in aws/aws-lambda-dotnet
Similar issues
-
type/automation type/tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
t/bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
ci-failure-cause test-failure
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area:auth FE mvp P3
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
klasolsson81/jobbliggaren#1788 ·