TypeScript and Lambda Serverless Project Limit

TypeScript and Lambda Serverless Project Limit

Recently, our project deployment met this exception while deploy
An error occurred: DevicePairingUpdatesLambdaFunction - Unzipped size must be smaller than 262144000 bytes (Service: AWSLambda; Status Code: 400; Error Code: InvalidParameterValueException; Request ID:xxxxxxx-11e8-81e6-xxxxxxx).

Look at the limitation for lambda in detail here
https://docs.aws.amazon.com/lambda/latest/dg/limits.html#limits-list
Lambda function deployment package size (compressed .zip/.jar file). 50MB
Size of code/dependencies that you can zip into a deployment package (uncompressed .zip/.jar size). 250

Currently, our projects are packaged and deployed in 2 different ways.
#1 serverless-plugin-typescript plugin
No webpack, no compress map file generated

Run the command >sls package and check the directory .serverless, there will be a zip file, unzip that, the structure will be as follow:
drwxr-xr-x 168 hluo staff 5376 Sep 6 16:36 node_modules
-rw-r--r-- 1 hluo staff 1017 Dec 31 1979 package.json
drwxr-xr-x 6 hluo staff 192 Sep 6 16:37 src

The good part for this plugin is that, all the shared dependencies will be under node_modules, the source codes in src directory are all small
-rw-r--r-- 1 hluo staff 2329 Dec 31 1979 accessToken.js
-rw-r--r-- 1 hluo staff 4686 Dec 31 1979 getVCSettings.js
-rw-r--r-- 1 hluo staff 2208 Dec 31 1979 handler.js
-rw-r--r-- 1 hluo staff 4413 Dec 31 1979 utils.js

So in this case, if you have 20 lambda in this serverless.yaml together, you will have all shared dependencies in node_modules, all lambda codes in src directory.
The bad side for this is that all these javascript files are normal files, no compress.

#2 serverless-webpack plugin
Compress map file generated for each lambda functions

Run the command >sls package and check the directory .serverless, there will be a zip file, unzip that, the structure will be as follow:
-rw-r--r-- 1 hluo staff 4.1M Jan 1 1980 handler.js
-rw-r--r-- 1 hluo staff 5.6M Jan 1 1980 handler.js.map

In this way, there is no node_modules, all related javascript dependencies will be compressed and packaged into the lambda js and js.map files.
The good thing is the files are compressed, so it is smaller than #1 comparing per lambda. But the downside for this plugin is you have no where to share dependencies. So if you have 20 lambda with similar dependencies in one serverless.yaml, you will have 20 bigger js and js.map files, that is why my size get over 50MB.

For example
-rw-r--r-- 1 hluo staff 7.3M Jan 1 1980 deleteDevicePairing.js
-rw-r--r-- 1 hluo staff 10M Jan 1 1980 deleteDevicePairing.js.map
-rw-r--r-- 1 hluo staff 7.3M Jan 1 1980 getPairedDevices.js
-rw-r--r-- 1 hluo staff 10M Jan 1 1980 getPairedDevices.js.map
-rw-r--r-- 1 hluo staff 7.3M Jan 1 1980 updateDevicePairing.js
-rw-r--r-- 1 hluo staff 10M Jan 1 1980 updateDevicePairing.js.map
-rw-r--r-- 1 hluo staff 7.3M Jan 1 1980 updateDeviceSystemName.js
-rw-r--r-- 1 hluo staff 10M Jan 1 1980 updateDeviceSystemName.js.map

I do not know if there are other solutions or plugins, but this is what I found in current situations.

References:
https://docs.aws.amazon.com/lambda/latest/dg/limits.html#limits-list
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值