Aws-sdk-js: How to use just S3 service out of the whole `aws-sdk`?

Created on 31 Aug 2016  路  4Comments  路  Source: aws/aws-sdk-js

I want to use just the S3 services to upload the object and get the list of objects.
The dist of aws-sdk is 1 MB, and i dont need everything, just the S3.
I am looking for something like this

import S3 from 'aws-sdk/s3'

or

import { S3 } from 'aws-sdk'
guidance

Most helpful comment

This is now available in 2.6.0:

import S3 from 'aws-sdk/clients/s3';

Take care to avoid any use of the default aws-sdk module, for example for default config or credentials, instead for now:

import 'aws-sdk/lib/node_loader'; // Hack needed before the first import
import { config } from 'aws-sdk/lib/core'; // or any other `aws-sdk` export

Hopefully this is cleaned up soon.

All 4 comments

@Sunil6591
Are you using 3rd party tools, like Webpack or Browserify in your project, or are you pulling in the SDK using script tags?
If you're doing the latter, you can use the browser SDK builder to generate an SDK with just the services you want:
https://sdk.amazonaws.com/builder/js/

We are currently working on better webpack support as part of #1117, and are also hoping to address importing individual services, but this is still a work in progress.

This is now available in 2.6.0:

import S3 from 'aws-sdk/clients/s3';

Take care to avoid any use of the default aws-sdk module, for example for default config or credentials, instead for now:

import 'aws-sdk/lib/node_loader'; // Hack needed before the first import
import { config } from 'aws-sdk/lib/core'; // or any other `aws-sdk` export

Hopefully this is cleaned up soon.

To build on top of what @simonbuchan said, if you're using webpack or browserify, you can now require individual services:

var S3 = require('aws-sdk/clients/s3');

You can also still access the AWS namespace that includes only services you've imported:

var AWS = require('aws-sdk/global');

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

Was this page helpful?
0 / 5 - 0 ratings