Aws-sdk-js: Implement the Lerna pattern.

Created on 1 Feb 2018  路  10Comments  路  Source: aws/aws-sdk-js

Problem

The aws-sdk is one of the largest packages I end up using. Most of the time I really only need a few clients out of the package as a whole. Where deploying to lambda the size of the dependencies must be considered, this can be a potential problem.

Solution

It would be nice for the project to follow and implement the lerna pattern. Packages such as lodash follow this pattern. It allows you to be able to require in the full SDK if you require it or require small components of the SDK. For example, instead of npm i -S aws-sdk you could:

npm i -S aws-sdk.s3 aws-sdk.lambda
const S3 = require('aws-sdk.s3');
const Lambda = require('aws-sdk.lambda');

The difference

You are still able to install the aws-sdk package from npm and use it the way it is used today. The SDK would still return all the clients. The difference would be each client from the aws-sdk would become its own package. (aws-sdk.s3, aws-sdk.lambda, ...) This allows others to be able to install only the clients they will use, instead of needing to install the general all inclusive aws-sdk.

feature-request needs-major-version

Most helpful comment

Hey everyone, this has been a known issue and hence the version 3 of the SDK takes care of it.

Please check JS-SDK-V3 which consists of modular packages and provides much more efficiency. The beta is out now.

All 10 comments

Hi @rizowski,

You can do this today by requiring specific service clients as submodules. There's a quick mention of this in the README, but essentially it ends up looking very much like the ideal example given above:

const S3 = require('aws-sdk/clients/s3');
const Lambda = require('aws-sdk/clients/lambda');

This can reduce the size of bundles produced by Webpack et al by a considerable margin, but it won't reduce the amount of code deployed to Lambda.

@jeskew Thanks for the quick response. The biggest thing I would like to get out of what I am proposing is being able to reduce code deployed to services other than front end. Although, by its very nature, implementing the lerna pattern could also produce smaller bundle sizes for webpack. 馃槃

+1. I've actually been bumping up against the Lambda total file size limit for months now. This would be significant.

I would definitely be happy to see smaller and independently versioned packages, so I don鈥檛 have to update aws-sdk when a client I鈥檓 not using gets updated.

Lerna (or equivalent) seems like a good solution to this, so I could just yarn add @aws/s3, which would depend on something like @aws/core, just like https://github.com/Turfjs/turf.

+1 also running into this.

As an alternative solution, what if aws-sdk was available on all lambdas by default? Seems like such a common dependency it would be nice if it were just available for you (and didn't count toward total size) similar to the base node stuff you can import.

@spilliton

aws-sdk is available in all Lambdas.

Lambda is currently using 2.290.0, but this page will be updated when that's moved to a newer version: Lambda Current Supported Versions

@srchase awesome I had no idea! Thanks!

sdk versions in lambdas in AWS are not updated anymore, due to backward compatibility problems.

existing tested and deployed lambdas could/would break if AWS updates the lambda in the environment from their side.

If you want to do anything on the aws-sdk currently without there being any partial imports, you could use AWS Lambda Layers.

+1 for lerna like modularity

+1 fr lerna. I'm only need to work with s3 but still need to install aws-sdk which the unpacked size is 47Mb.

Hey everyone, this has been a known issue and hence the version 3 of the SDK takes care of it.

Please check JS-SDK-V3 which consists of modular packages and provides much more efficiency. The beta is out now.

Was this page helpful?
0 / 5 - 0 ratings