I am creating a handler in AWS lambda that returns a file for my Single Page Application(SPA). The function runs fast (couple of ms).But still I have to run it multiple times, almost simultaneously, and then they timeout. My timeout is 60 seconds. I think that has something to do with docker but I am not so sure. Is there something I can do?
Here is my code:pastebin.com/TdqAu3Gx
! Even with other functions it takes mush more time to get the response, compared to the execution time.
After some time I published the front-end on Netlify. But after making some functions I encountered the same bug. The fowoling code works in aws sam local.
package main
import (
"fmt"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
type MyReq struct {
Username string `json:"username"`
}
func handler(m events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
// log.Println(m.Username)
fmt.Println("
", m.Body, "
")
return events.APIGatewayProxyResponse{
Body: m.Body,
}, nil
}
func main() {
lambda.Start(handler)
}
But does not work in the real was lambda. (It works but I get the full json as text for exaple headers are not set on response, but i can see them as text in the body). If I change events.APIGatewayProxyResponse
and events.APIGatewayProxyRequest
to MyRequest
and a string respectively it works in lambda but timeouts in sam local. In my template.json
under Resources
I have :
"TestFunction": {
"Type": "AWS::Serverless::Function",
"Properties": {
"CodeUri": "MY_BUCKET",
"Handler": "testf",
"Role": "My Lambda role",
"Events": {
"RegisterEvent": {
"Type": "Api",
"Properties": {
"Path": "/testf",
"Method": "POST"
}
}
}
}
}
How can I make the code work both on AWS Lambda and SAM Local? If someone has a working template of a sam app that works both on SAM and AWS and can open source it, I would be very thankful.