First of all congratulations, that you were able to successfully identify the issue. However, there are many concepts that can be learnt from the occurred issue. Let’s discuss few of them.
Lambda cold start issue
To understand the concept of cold start in lambda it is inevitable to go any further without understanding how AWS Lambda works. Please refer to the undermentioned link which explains the overall working of lambda as shared in AWS re:Invent 2018
AWS Lambda under the hood (Video Link) : https://www.youtube.com/watch?v=QdzV04T_kec
Coming back to the issue of cold start, as our lambda functions are executed in a container, post execution the container gets killed if there are no further function invocations within ~15 minutes of inactivity. Once the container is killed, any future call to execute the same function will require setting up a new container which can take >5 seconds (most probable reason behind your api call getting terminated post 6 seconds). However, there are many available options available that can keep your lambda warm. Please refer the undermentioned link from Serverless community.
Keeping Lambda Functions Warm (Blog Link) : https://serverless.com/blog/keep-your-lambdas-warm/
Increasing Lambda timeout
“I had to go into the AWS console and increase the timeout to 20 seconds”.
Although, this approach is totally acceptable but since you are using server less technology (explicit serverless.yml file), you can directly change the default lambda timeout period (which is 6 seconds). Please refer to the undermentioned code snippet and link for further understanding.
provider: name: was runtime: nodejs6.10 memorySize: 512 # optional, in MB, default is 1024 timeout: 10 # optional, in seconds, default is 6
Serverless AWS Lambda function Guide (Blog Link) : https://serverless.com/framework/docs/providers/aws/guide/functions/