Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda GoLang Errors

Tags:

go

aws-lambda

Is it OK to panic() when failed to create AWS session? As an opposite, I can just return the error from my handler function (in this case I have to create the session in the handler code, but not in the init()).

The docs say

Lambda will re-create the function automatically

Does it mean the panic always causes the cold-start and is preferred to return error from the handler?

like image 590
S2201 Avatar asked May 22 '18 09:05

S2201


People also ask

Is Golang good for AWS Lambda?

Go is a great fit when it comes to AWS Lambda. Go brings the advantage of type safety, as it is a statically typed language, lightweight, and performant code, and has a robust tooling system built in. To follow along, you will need to have the following installed: Go 1.15 or later to use the Go AWS SDK V2.

What happens if a Lambda function fails?

You can retry, send the event to a queue for debugging, or ignore the error. Your function's code might have run completely, partially, or not at all. If you retry, ensure that your function's code can handle the same event multiple times without causing duplicate transactions or other unwanted side effects.

How do you check Lambda error?

To troubleshoot Lambda code errors You can use CloudWatch to view all logs generated by your function's code and identify potential issues. For more information, see Accessing Amazon CloudWatch Logs for AWS Lambda.


1 Answers

Yes. A panic will trigger a cold restart of your code. The use of panic should be reserved for exceptional circumstances; returning an error is to be preferred in most circumstances.

like image 89
Venantius Avatar answered Nov 15 '22 08:11

Venantius