API Gateway - round trip from browser about 150ms
Cloudfront proxying to direct lambda - round trip from browser about 120ms
Directly calling lambda - round trip from browser about 60ms
Now this is only one function I am testing and I only clicked on it about ten times, but what I am observing here is that each layer of AWS the call goes through adds 30ms. I suspect this has to do with https and the encypt/decrypt between each box. For example API gateway is going through three boxes - Cloudfront, API Gateway, Lambda. So that is six encryption points.
On the other hand, 60ms to go 650 miles, hit lambda, do a database read, and return 30 results is pretty good considering the speed of light round trip is 8ms of that. And this is not a do-nothing db read. Everything is running on a Cognito user ID and the last 30 results are returned for that specific user.
I’m bugging the AWS Go SDK people to make some things more efficient. If they do what I’m asking it should take another 10ms off from my lambda run time.
Edit: I do see considerable variability in these numbers. It is likely the impact of other traffic getting in the way.
Edit2: Direct lambda calls support CORS. The options request comes back with access-control-max-age: 172800 which causes the CORS status to be cached for two days.