[英]How do I use a custom AWS SDK with nodejs?
I want to make a nodejs application that uses the AWS SDK.我想制作一个使用 AWS SDK 的 nodejs 应用程序。 However, it only really needs to use S3, and I want the application to have a small filesize.
但是,它只需要真正使用 S3,并且我希望应用程序具有较小的文件大小。
AWS has a custom sdk builder which should make a custom SDK with only the required packages. AWS 有一个自定义 sdk 构建器,它应该只使用所需的包制作自定义 SDK。 Unfortunately, this doesn't work, even when I select all of the services.
不幸的是,这不起作用,即使我选择了所有服务。 How do I make a custom SDK that works with node?
如何制作与 node 一起使用的自定义 SDK?
I've tried using the npm install aws-sdk
, and that works, but it's 40MB.我试过使用
npm install aws-sdk
,它有效,但它是 40MB。 I've also tried selecting all of the services in the service builder (only 3MB), but that doesn't work.我还尝试选择服务构建器中的所有服务(只有 3MB),但这不起作用。
It always gives an error at this line:它总是在这一行给出错误:
var aws = require("./aws-sdk-2.462.0.min.js");
ReferenceError: AWS is not defined
at Object.<anonymous> (/home/cwaugh/workspaces/meta-lambda/aws-sdk-2.462.0.min.js:7:30180)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/cwaugh/workspaces/meta-lambda/handler.js:5:11)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
That's the browser SDK.那就是浏览器SDK。 For Node you can use this module which only provides an S3 Client.
对于 Node,你可以使用这个模块,它只提供一个 S3 客户端。 That page has a clear example showing how to call putObject using this custom SDK.
该页面有一个清晰的示例,展示了如何使用此自定义 SDK 调用 putObject。
There's many different individual modules for a variety of AWS services.对于各种 AWS 服务,有许多不同的单独模块。 You can find more information here .
您可以在此处找到更多信息。
This is now possible with AWS SDK for JavaScript v3现在可以使用适用于 JavaScript 的 AWS 开发工具包 v3
You can install only the required packages as follows :您可以仅安装所需的软件包,如下所示:
npm install @aws-sdk/client-s3
Use them as :将它们用作:
const {S3} = require('@aws-sdk/client-s3');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.