Creating and calling service objects - Amazon SDK for JavaScript
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

The Amazon SDK for JavaScript V3 API Reference Guide describes in detail all the API operations for the Amazon SDK for JavaScript version 3 (V3).

Starting October 1, 2022, Amazon SDK for JavaScript (v3) will end support for Internet Explorer 11 (IE 11). For details, see Announcing the end of support for Internet Explorer 11 in the Amazon SDK for JavaScript (v3).

Creating and calling service objects

The JavaScript API supports most available Amazon services. Each service in the JavaScript API provides a client class with a send method that you use to to invoke every API the service supports. For more information about service classes, operations, and parameters in the JavaScript API, see the API Reference.

When using the SDK in Node.js, you add the SDK package for each service you need to your application using import, which provides support for all current services. The following example creates an Amazon S3 service object in the us-west-1 Region.

// Import the Amazon S3 service client import {S3} from "@aws-sdk/client-s3"; // Create an S3 client in the us-west-1 Region const s3Client = new S3.S3Client({ region: "us-west-1" });

Specifying service object parameters

When calling a method of a service object, pass parameters in JSON as required by the API. For example, in Amazon S3, to get an object for a specified bucket and key, pass the following parameters to the GetObject method. For more information about passing JSON parameters, see Working with JSON.

s3.getObject({Bucket: 'bucketName', Key: 'keyName'});

You can also call the GetObjectCommand method from the S3Client:

s3Client.send(new GetObjectCommand({Bucket: 'bucketName', Key: 'keyName'}));

For more information about Amazon S3 parameters, see Class: S3 in the API Reference.