AWS Lambda GoLang错误

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?

The answer depends on what is going on in init section.

If you create session clients to connect to other services it might be good to panic and cause cold-start than continue container's lifecycle with the failed clients.

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.