Convert Figma logo to code with AI

aws logoaws-sdk-js

AWS SDK for JavaScript in the browser and Node.js

7,592
1,547
7,592
1

Top Related Projects

Google Cloud Client Library for Node.js

Modularized AWS SDK for JavaScript.

The repository for high quality TypeScript type definitions.

⚡ Serverless Framework – Effortlessly build apps that auto-scale, incur zero costs when idle, and require minimal maintenance using AWS Lambda and other managed cloud services.

20,922

Pulumi - Infrastructure as Code in any programming language 🚀

Quick Overview

The aws/aws-sdk-js repository contains the official AWS SDK for JavaScript, which allows developers to interact with various AWS services from their JavaScript applications. The SDK provides a comprehensive set of APIs and utilities to simplify the process of working with AWS resources, making it easier to build and deploy cloud-based applications.

Pros

  • Comprehensive Coverage: The SDK supports a wide range of AWS services, including EC2, S3, DynamoDB, Lambda, and many others, allowing developers to interact with a variety of AWS resources.
  • Cross-Platform Compatibility: The SDK can be used in both browser-based and server-side (Node.js) JavaScript applications, providing a consistent development experience across different environments.
  • Actively Maintained: The SDK is actively maintained by the AWS team, with regular updates and bug fixes to ensure compatibility with the latest AWS services and features.
  • Extensive Documentation: The SDK comes with detailed documentation, including API references, code examples, and guides, making it easier for developers to get started and troubleshoot issues.

Cons

  • Complexity: The SDK can be complex, especially for developers new to AWS, as it requires understanding of various AWS services and their respective APIs.
  • Performance Overhead: The SDK can add some performance overhead to applications, particularly for simple operations that could be handled more efficiently using lower-level AWS APIs.
  • Dependency on AWS: The SDK is tightly coupled with AWS, which means that applications using the SDK are heavily dependent on the AWS ecosystem and may face challenges if they need to migrate to other cloud providers.
  • Versioning Challenges: The SDK is frequently updated to support new AWS services and features, which can sometimes lead to versioning challenges and compatibility issues when upgrading to newer versions.

Code Examples

Here are a few examples of how to use the AWS SDK for JavaScript:

  1. Uploading a file to S3:
const AWS = require('aws-sdk');
const fs = require('fs');

const s3 = new AWS.S3();

const uploadFile = async () => {
  try {
    await s3
      .upload({
        Bucket: 'my-bucket',
        Key: 'my-file.txt',
        Body: fs.createReadStream('path/to/file.txt'),
      })
      .promise();
    console.log('File uploaded successfully');
  } catch (err) {
    console.error('Error uploading file:', err);
  }
};

uploadFile();
  1. Querying DynamoDB:
const AWS = require('aws-sdk');

const dynamodb = new AWS.DynamoDB.DocumentClient();

const queryItems = async () => {
  try {
    const result = await dynamodb
      .query({
        TableName: 'my-table',
        KeyConditionExpression: 'id = :id',
        ExpressionAttributeValues: {
          ':id': '123',
        },
      })
      .promise();
    console.log('Query result:', result.Items);
  } catch (err) {
    console.error('Error querying DynamoDB:', err);
  }
};

queryItems();
  1. Invoking a Lambda function:
const AWS = require('aws-sdk');

const lambda = new AWS.Lambda();

const invokeLambda = async () => {
  try {
    const result = await lambda
      .invoke({
        FunctionName: 'my-lambda-function',
        Payload: JSON.stringify({ message: 'Hello, AWS Lambda!' }),
      })
      .promise();
    console.log('Lambda function response:', result.Payload);
  } catch (err) {
    console.error('Error invoking Lambda function:', err);
  }
};

invokeLambda();

Getting Started

To get started with the AWS SDK for JavaScript, follow these steps:

  1. Install the SDK using npm:
npm install aws-sdk
  1. Import the SDK in your JavaScript file:
const AWS = require('aws-sdk');
  1. Configure the SDK with your AWS credentials:
AWS.config.update({
  accessKeyId: 'your-access-key-id',
  secretAccessKey: 'your

Competitor Comparisons

Google Cloud Client Library for Node.js

Pros of googleapis/google-cloud-node

  • Comprehensive Documentation: The googleapis/google-cloud-node repository provides extensive documentation, making it easier for developers to understand and use the library.
  • Modular Design: The library is designed in a modular fashion, allowing developers to only import the specific services they need, reducing the overall bundle size.
  • Active Community: The repository has a large and active community, with frequent updates and contributions from developers.

Cons of googleapis/google-cloud-node

  • Complexity: The library can be complex to set up and configure, especially for developers new to the Google Cloud Platform.
  • Performance: The library may have slightly higher overhead compared to the aws/aws-sdk-js, due to the additional abstraction layers.

Code Comparison

aws/aws-sdk-js:

const AWS = require('aws-sdk');
AWS.config.update({ region: 'us-west-2' });

const s3 = new AWS.S3();
s3.listBuckets((err, data) => {
  if (err) console.log(err, err.stack);
  else console.log(data.Buckets);
});

googleapis/google-cloud-node:

const { Storage } = require('@google-cloud/storage');
const storage = new Storage();

storage.getBuckets()
  .then((results) => {
    const buckets = results[0];
    console.log('Buckets:');
    buckets.forEach((bucket) => {
      console.log(bucket.name);
    });
  })
  .catch((err) => {
    console.error('ERROR:', err);
  });

Modularized AWS SDK for JavaScript.

Pros of aws/aws-sdk-js-v3

  • Modular Design: aws/aws-sdk-js-v3 follows a modular design, allowing developers to import only the necessary services, reducing the overall bundle size and improving performance.
  • Improved Typing: The v3 SDK provides better TypeScript support, with more accurate type definitions and improved type inference.
  • Asynchronous Handling: The v3 SDK uses native JavaScript Promises and async/await syntax, simplifying asynchronous code handling.

Cons of aws/aws-sdk-js-v3

  • Breaking Changes: Upgrading from the v2 SDK to the v3 SDK may require significant code changes due to the breaking changes introduced.
  • Steeper Learning Curve: The modular design and new features of the v3 SDK may require developers to invest more time in learning the new API and patterns.
  • Reduced Community Support: The v2 SDK has a larger user base and more community resources, while the v3 SDK is still relatively new.

Code Comparison

aws/aws-sdk-js (v2)

const AWS = require('aws-sdk');
AWS.config.update({ region: 'us-west-2' });

const s3 = new AWS.S3();
s3.listBuckets((err, data) => {
  if (err) console.log(err, err.stack);
  else console.log(data.Buckets);
});

aws/aws-sdk-js-v3

import { S3Client, ListBucketsCommand } from "@aws-sdk/client-s3";

const s3Client = new S3Client({ region: "us-west-2" });
const command = new ListBucketsCommand({});

const response = await s3Client.send(command);
console.log(response.Buckets);

The repository for high quality TypeScript type definitions.

Pros of DefinitelyTyped/DefinitelyTyped

  • Provides type definitions for a vast number of JavaScript libraries and frameworks, making it easier to work with them in TypeScript.
  • Allows the community to contribute and maintain type definitions, ensuring they stay up-to-date.
  • Helps catch type-related errors during development, improving code quality and maintainability.

Cons of DefinitelyTyped/DefinitelyTyped

  • The repository can be large and complex, with thousands of type definitions, which can make it challenging to navigate and find the right definitions.
  • The quality of type definitions can vary, as they are contributed by the community, and some may not be as accurate or complete as others.
  • Relying on DefinitelyTyped can introduce an additional dependency in your project, which may not be desirable in some cases.

Code Comparison

AWS SDK for JavaScript:

const AWS = require('aws-sdk');
AWS.config.update({
  region: 'us-west-2',
  accessKeyId: 'YOUR_ACCESS_KEY_ID',
  secretAccessKey: 'YOUR_SECRET_ACCESS_KEY'
});

const s3 = new AWS.S3();
s3.listBuckets((err, data) => {
  if (err) console.log(err, err.stack);
  else console.log(data.Buckets);
});

DefinitelyTyped type definition:

import * as AWS from 'aws-sdk';

AWS.config.update({
  region: 'us-west-2',
  accessKeyId: 'YOUR_ACCESS_KEY_ID',
  secretAccessKey: 'YOUR_SECRET_ACCESS_KEY'
});

const s3 = new AWS.S3();
s3.listBuckets((err: AWS.AWSError, data: AWS.S3.ListBucketsOutput) => {
  if (err) console.log(err, err.stack);
  else console.log(data.Buckets);
});

⚡ Serverless Framework – Effortlessly build apps that auto-scale, incur zero costs when idle, and require minimal maintenance using AWS Lambda and other managed cloud services.

Pros of Serverless

  • Serverless provides a higher-level abstraction for building serverless applications, making it easier to manage and deploy functions, events, and resources.
  • Serverless has a rich ecosystem of plugins and integrations, allowing developers to extend the framework's functionality.
  • Serverless simplifies the deployment process, handling tasks like packaging, versioning, and provisioning of resources.

Cons of Serverless

  • Serverless may have a steeper learning curve compared to the AWS SDK, as it introduces its own set of concepts and configuration.
  • Serverless may be less flexible than the AWS SDK, as it enforces a specific structure and workflow for building serverless applications.

Code Comparison

AWS SDK:

const AWS = require('aws-sdk');
const s3 = new AWS.S3();

s3.listBuckets((err, data) => {
  if (err) {
    console.error(err);
  } else {
    console.log(data.Buckets);
  }
});

Serverless:

'use strict';

module.exports.hello = async (event) => {
  return {
    statusCode: 200,
    body: JSON.stringify({
      message: 'Hello from Serverless!',
    }),
  };
};
20,922

Pulumi - Infrastructure as Code in any programming language 🚀

Pros of Pulumi

  • Pulumi provides a more modern and expressive programming model for infrastructure as code, allowing developers to use familiar programming languages like TypeScript, Python, and Go.
  • Pulumi's multi-cloud support enables managing resources across different cloud providers, including AWS, Azure, and Google Cloud, within a single codebase.
  • Pulumi's state management and deployment capabilities offer a more streamlined and efficient infrastructure management experience compared to the AWS SDK.

Cons of Pulumi

  • Pulumi has a steeper learning curve compared to the AWS SDK, as it requires developers to learn a new programming model and ecosystem.
  • Pulumi's pricing model may be more expensive for small-scale projects or individual developers, as it has a subscription-based pricing structure.

Code Comparison

AWS SDK:

const AWS = require('aws-sdk');
const s3 = new AWS.S3();

s3.createBucket({
  Bucket: 'my-bucket'
}, (err, data) => {
  if (err) {
    console.error(err);
  } else {
    console.log('Bucket created:', data.Location);
  }
});

Pulumi:

import * as aws from "@pulumi/aws";

const bucket = new aws.s3.Bucket("my-bucket");

console.log(`Bucket created: ${bucket.id}`);

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

AWS SDK for JavaScript

NPM version

In Maintenance Mode as of September 8, 2024

The AWS SDK for JavaScript v2 has entered maintenance mode on September 8, 2024 and will be reaching end-of-support on September 8, 2025. During maintenance mode, AWS will limit SDK releases to address critical bug fixes and security issues only. The SDK will not receive API updates for new or existing services, or be updated to support new regions.

We recommend that you migrate to AWS SDK for JavaScript v3. For dates, additional details, and information on how to migrate, please refer to the linked announcement.

The AWS SDK for JavaScript v3 is the latest and recommended version, which has been GA since December 2020. Here is why and how you should use AWS SDK for JavaScript v3. You can try our migration scripts in aws-sdk-js-codemod to migrate your application from v2 to v3.

To get help with your migration, please follow our general guidelines to open an issue and choose guidance. To give feedback on and report issues in the v3 repo, please refer to Giving feedback and contributing.

Watch this README and the AWS Developer Tools Blog for updates and announcements regarding the maintenance plans and timelines.

A maintenance mode message may be emitted by this package on startup. To suppress this message, use an environment variable:

AWS_SDK_JS_SUPPRESS_MAINTENANCE_MODE_MESSAGE=1 node my_program.js

or a JavaScript setting as follows:

var SDK = require('aws-sdk');
require('aws-sdk/lib/maintenance_mode_message').suppress = true;

Table of Contents:

Getting Started

How To Install

In the Browser

To use the SDK in the browser, simply add the following script tag to your HTML pages:

<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1691.0.min.js"></script>

You can also build a custom browser SDK with your specified set of AWS services. This can allow you to reduce the SDK's size, specify different API versions of services, or use AWS services that don't currently support CORS if you are working in an environment that does not enforce CORS. To get started:

http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/building-sdk-for-browsers.html

The AWS SDK is also compatible with browserify.

For browser-based web, mobile and hybrid apps, you can use AWS Amplify Library which extends the AWS SDK and provides an easier and declarative interface.

In Node.js

The preferred way to install the AWS SDK for Node.js is to use the npm package manager for Node.js. Simply type the following into a terminal window:

npm install aws-sdk

In React Native

To use the SDK in a react native project, first install the SDK using npm:

npm install aws-sdk

Then within your application, you can reference the react native compatible version of the SDK with the following:

var AWS = require('aws-sdk/dist/aws-sdk-react-native');

Alternatively, you can use AWS Amplify Library which extends AWS SDK and provides React Native UI components and CLI support to work with AWS services.

Using Bower

You can also use Bower to install the SDK by typing the following into a terminal window:

bower install aws-sdk-js

Usage with TypeScript

The AWS SDK for JavaScript bundles TypeScript definition files for use in TypeScript projects and to support tools that can read .d.ts files. Our goal is to keep these TypeScript definition files updated with each release for any public api.

Pre-requisites

Before you can begin using these TypeScript definitions with your project, you need to make sure your project meets a few of these requirements:

  • Use latest version of TypeScript. We recommend 4.x+

  • Includes the TypeScript definitions for node. You can use npm to install this by typing the following into a terminal window:

    npm install --save-dev @types/node
    
  • If you are targeting at es5 or older ECMA standards, your tsconfig.json has to include 'es5' and 'es2015.promise' under compilerOptions.lib. See tsconfig.json for an example.

In the Browser

To use the TypeScript definition files with the global AWS object in a front-end project, add the following line to the top of your JavaScript file:

/// <reference types="aws-sdk" />

This will provide support for the global AWS object.

In Node.js

To use the TypeScript definition files within a Node.js project, simply import aws-sdk as you normally would.

In a TypeScript file:

// import entire SDK
import AWS from 'aws-sdk';
// import AWS object without services
import AWS from 'aws-sdk/global';
// import individual service
import S3 from 'aws-sdk/clients/s3';

NOTE: You need to add "esModuleInterop": true to compilerOptions of your tsconfig.json. If not possible, use like import * as AWS from 'aws-sdk'.

In a JavaScript file:

// import entire SDK
var AWS = require('aws-sdk');
// import AWS object without services
var AWS = require('aws-sdk/global');
// import individual service
var S3 = require('aws-sdk/clients/s3');

With React

To create React applications with AWS SDK, you can use AWS Amplify Library which provides React components and CLI support to work with AWS services.

With Angular

Due to the SDK's reliance on node.js typings, you may encounter compilation issues when using the typings provided by the SDK in an Angular project created using the Angular CLI.

To resolve these issues, either add "types": ["node"] to the project's tsconfig.app.json file, or remove the "types" field entirely.

AWS Amplify Library provides Angular components and CLI support to work with AWS services.

Known Limitations

There are a few known limitations with the bundled TypeScript definitions at this time:

  • Service client typings reflect the latest apiVersion, regardless of which apiVersion is specified when creating a client.
  • Service-bound parameters use the any type.

Getting Help

The best way to interact with our team is through GitHub. You can open an issue and choose from one of our templates for bug reports, feature requests or guidance. You may also find help on community resources such as StackOverFlow with the tag #aws-sdk-js. If you have a support plan with AWS Support, you can also create a new support case.

Please make sure to check out our resources too before opening an issue:

Please see SERVICES.md for a list of supported services.

Maintenance and support for SDK major versions

For information about maintenance and support for SDK major versions and their underlying dependencies, see the following in the AWS SDKs and Tools Shared Configuration and Credentials Reference Guide:

Contributing

We welcome community contributions and pull requests. See CONTRIBUTING.md for information on how to set up a development environment and submit code.

License

This SDK is distributed under the Apache License, Version 2.0, see LICENSE.txt and NOTICE.txt for more information.

NPM DownloadsLast 30 Days