API Gateway edge-optimized added latency

Viewed 1647

I have a Lambda function that is executed through API Gateway. If I request the endpoint directly: https://9ishqo5dj7.execute-api.us-east-1.amazonaws.com/api/

Then the execution time average is 200ms:

direct latency

However, if I add an "edge-optimized" endpoint, like this: https://testsite.learn-serverless.org/

Then the execution time is higher:

cloudfront latency

It seems CloudFront is adding some noticeable latency instead of reducing it.

At first I thought (as explained here https://stackoverflow.com/a/49845124/72350) it could be because the website that I used to run the tests run inside AWS and going out of the AWS network to go to CF could add some latency, however, I've tried the same thing from a computer in South America and I get the same results:

CURL to https://9ishqo5dj7.execute-api.us-east-1.amazonaws.com/api/:

Lookup Time: 0,029
Connect Time: 0,078
AppCon Time: 0,382
Redirect Time: 0,000
Pre-transfer Time: 0,382
Start-transfer Time: 0,578

Total Time: 0,578

CURL to https://testsite.learn-serverless.org/:

Lookup Time: 0,125
Connect Time: 0,175
AppCon Time: 0,476
Redirect Time: 0,000
Pre-transfer Time: 0,477
Start-transfer Time: 1,074

Total Time: 1,074

Other test from Chicago, IL (using webpagetest.org), lead to the same results. TTFB: 440ms vs 730ms.

Any ideas?

Lambda function code: basic function with Python+Chalice, https://github.com/diegojancic/serverless-performance/tree/master/functions/chalice/base

Page used to test latency: https://latency.apex.sh

Alternate Regional APIG endpoint: https://testsite2.learn-serverless.org

UPDATE 1: One thing to note is how Route53 is configured:

route53 configuration

It's set as a standard CNAME, if I set it as an CNAME-"ALIAS", it doesn't work for some reason. Not sure if this can have side-effects, but thought it could be worth mentioning.

0 Answers
Related