Posting our findings when using Serverless 1.0.0 beta 2 with CircleCI.
We’re building a number of services for AWS API Gateway/Lambda service and obviously wanted to deploy from Circle. Since we already had some Serverless 0.5.x projects, we didn’t want to install Serverless 1.0 globally, so decided to include it as a dev dependency in each individual project. Once we’ve migrated everything to sls 1.0 we’ll most likely remove the dependency.
This worked fine locally where we could run sls deploy --stage dev
with no problems. Once we tried to define a deployment into our circleCI config we found that the deployment was hanging 95% of the time, but often at different points in the deployment process and every now and then it would work.
With some help from the guys at Circle we determined that the zip file created by serverless to deploy to S3 was huge and causing our build instance to run out of memory. From this we realised that the default serverless deploy includes the whole node_modules
directory in its zip file and doesn’t exclude dev dependencies.
To deal with this, we’re using the serverless-webpack
plugin that allows us to reduce the size of the zip file to include only the dependencies needed for our lambda function. We got the added bonus of being able to transpile with babel as part of the typical webpack process.
Note that some node modules don’t like being parsed by babel or included by webpack (eg pusher). To avoid problems here, we define all node_modules as external to webpack, and then include the required runtime dependencies explicitly in the plugin config in serverless.yml
Hope this help others avoid wasting time on build/deploy problems.