~ 戲法 λ λ 會變 各有巧妙不同 ~
Figure. λ 開啟了我 AWS 人生的入口
今天我們來討論一下 AWS Lambda 上的限制以及最佳實務吧
| Resource | Limit | 
|---|---|
| Function memory allocation(記憶體分配限制) | 128 MB ~ 3,008 MB in 64 MB increments | 
| Function timeout(執行時間限制) | 900 seconds (15 min) | 
| Invocation frequency per region(requests per second) | 10 x concurrent executions limit (synchronous - all sources)10 x concurrent executions limit (asynchronous - all non-sources)Unlimited (asynchronous - AWS service sources) | 
| Invocation Payload(叫用 payload 大小限制) | 6 MB (synchronous)256 KB (asynchronous) | 
| Deployment package size(部署檔案大小限制) | 50 MB (zipped, for direct upload)250 MB (unzipped, including layers)3 MB (console editor) | 
| /tmp directory storage(暫存檔案大小限制) | 512 MB | 
| File descriptors(最大可開啟檔案數量限制) | 1,024 | 
| Execution processes / threads(最大可開執行緒數量限制) | 1,024 | 
有幾點需要注意:
儘量把核心功能封裝,在 handler 裡面的程式碼相依性越少越好,這樣會有利於測試
舉個例,我們可以把一般的功能流程會大致分成三項工作:輸入驗證、執行業務邏輯、產生回傳值
response handler (event, context){
    boolean validate(input);
    result = doWork();
    response = buildResponse(result);
    return response;
}
https://aws.plainenglish.io/best-practices-for-python-with-aws-lambda-an-essential-guide-a22b708f8006
https://medium.com/@TechTim42/aws-lambda-limit-and-features-everyone-should-know-d115f933608e
https://lumigo.io/aws-lambda-performance-optimization/aws-lambda-limits/