Reputation: 3530
I'm using Lambda functions (Nodejs runtime) on my project and using some of the modules from aws-sdk
.
So far, I've installed the entire aws-sdk
and I'm requiring each package separately like this:
const ApiGatewayManagementApi = require('aws-sdk/clients/apigatewaymanagementapi');
This works, but the issue is that I need to install the entire aws-sdk, which is big, and thus makes my function package big.
Is there a way to only install the modules I will actually use?
I've tried this:
$ npm install aws-sdk/clients/apigatewaymanagementapi --save
Which gives me the following errors:
npm ERR! code ENOLOCAL
npm ERR! Could not install from "aws-sdk/clients/apigatewaymanagementapi" as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/gustavocsdc/.npm/_logs/2019-05-16T02_32_28_129Z-debug.log
Upvotes: 4
Views: 2588
Reputation: 33779
Regrettably, with the current version (2.x) of the AWS JavaScript SDK this is not possible. There is a new AWS SDK for JavaScript V3 in the makings that will address this issues but it is still in "Developer Preview" (May 16, 2019).
Meanwhile, you are encouraged to install the full aws-sdk
for your JavaScript Lambda functions. The Lambda Application Best Practices states that:
Control the dependencies in your function's deployment package. The AWS Lambda execution environment contains a number of libraries such as the AWS SDK for the Node.js and Python runtimes (a full list can be found here: AWS Lambda Runtimes). To enable the latest set of features and security updates, Lambda will periodically update these libraries. These updates may introduce subtle changes to the behavior of your Lambda function. To have full control of the dependencies your function uses, we recommend packaging all your dependencies with your deployment package.
As can be seen, it is not a strict requirement to include the sdk in the Lambda package (thus decreasing its size) if you are willing to make the tradeoffs mentioned. Another reason why you might consider to provide the aws-sdk
as part of your package is that there may be a new feature in a more recent release of the sdk that you would like to use that is not the present in sdk provided by the runtime.
For completeness, the nodejs10.x
runtime provides version 2.437.0
of the aws-sdk
and the nodejs8.10
runtime provides version 2.290.0
aws-sdk
according to the AWS Lambda Runtimes.
Upvotes: 4