Amazon Web Services S3 support for Node.js

Support for AWS S3.

Link Type

Methods from SDK V2 s3client

import {AWS} from 'aws-sdk'
const s3client = new AWS.S3()

Methods from SDK V3 s3client

import {S3} from '@aws-sdk/client-s3'
const s3client = new S3()

Commands from SDK V3

imported from '@aws-sdk/client-s3'

No Link
  • createBucket

  • CreateBucketCommand
callLink
  • createMultipartUpload

  • createPresignedPost

  • abortMultipartUpload

  • completeMultipartUpload

  • deleteBucketAnalyticsConfiguration

  • deleteBucketCors

  • deleteBucketEncryption

  • deleteBucketInventoryConfiguration

  • deleteBucketLifecycle

  • deleteBucketMetricsConfiguration

  • deleteBucketPolicy

  • deleteBucketReplication

  • deleteBucketTagging

  • deleteBucketWebsite

  • deleteObjectTagging

  • deletePublicAccessBlock

  • getBucketAccelerateConfiguration

  • getBucketAcl

  • getBucketAnalyticsConfiguration

  • getBucketCors

  • getBucketEncryption

  • getBucketInventoryConfiguration

  • getBucketLifecycle

  • getBucketLifecycleConfiguration

  • getBucketLocation

  • getBucketLogging

  • getBucketMetricsConfiguration

  • getBucketNotification

  • getBucketNotificationConfiguration

  • getBucketPolicy

  • getBucketPolicyStatus

  • getBucketReplication

  • getBucketTagging

  • getBucketVersioning

  • getBucketWebsite

  • getObjectAcl

  • getObjectLegalHold

  • getObjectLockConfiguration

  • getObjectRetention

  • getObjectTagging

  • getPublicAccessBlock

  • getSignedUrl

  • listBuckets
  • listBucketAnalyticsConfigurations

  • listBucketInventoryConfigurations

  • listBucketMetricsConfigurations

  • listMultipartUploads

  • listObjectVersions

  • listParts

  • putBucketLogging
  • putBucketAnalyticsConfiguration
  • putBucketLifecycleConfiguration

  • putBucketMetricsConfiguration

  • putBucketNotification

  • putBucketNotificationConfiguration

  • putBucketPolicy

  • putBucketReplication

  • putBucketRequestPayment

  • putBucketTagging

  • putBucketVersioning

  • putObjectAcl

  • putObjectLegalHold

  • putObjectLockConfiguration

  • putObjectRetention

  • putObjectTagging

  • putPublicAccessBlock

  • putBucketAccelerateConfiguration

  • putBucketAcl

  • putBucketCors

  • putBucketEncryption

  • putBucketInventoryConfiguration

  • putBucketLifecycle

  • putBucketLogging
  • upload

  • uploadPart

  • uploadPartCopy

  • abortMultipartUpload
  • completeMultipartUpload
  • copyObject
  • createBucket
  • createMultipartUpload
  • deleteBucket
  • deleteBucketAnalyticsConfiguration
  • deleteBucketCors
  • deleteBucketEncryption
  • deleteBucketIntelligentTieringConfiguration
  • deleteBucketInventoryConfiguration
  • deleteBucketLifecycle
  • deleteBucketMetricsConfiguration
  • deleteBucketOwnershipControls
  • deleteBucketPolicy
  • deleteBucketReplication
  • deleteBucketTagging
  • deleteBucketWebsite
  • deleteObjectTagging
  • deletePublicAccessBlock
  • destroy
  • getBucketAccelerateConfiguration
  • getBucketAcl
  • getBucketAnalyticsConfiguration
  • getBucketCors
  • getBucketEncryption
  • getBucketIntelligentTieringConfiguration
  • getBucketInventoryConfiguration
  • getBucketLifecycleConfiguration
  • getBucketLocation
  • getBucketLogging
  • getBucketMetricsConfiguration
  • getBucketNotificationConfiguration
  • getBucketOwnershipControls
  • getBucketPolicy
  • getBucketPolicyStatus
  • getBucketReplication
  • getBucketRequestPayment
  • getBucketTagging
  • getBucketVersioning
  • getBucketWebsite
  • getObjectAcl
  • getObjectLegalHold
  • getObjectLockConfiguration
  • getObjectRetention
  • getObjectTagging
  • getPublicAccessBlock
  • headBucket
  • headObject
  • listBucketAnalyticsConfigurations
  • listBucketIntelligentTieringConfigurations
  • listBucketInventoryConfigurations
  • listBucketMetricsConfigurations
  • listBuckets
  • listMultipartUploads
  • listObjectVersions
  • listParts
  • putBucketAccelerateConfiguration
  • putBucketAcl
  • putBucketCors
  • putBucketEncryption
  • putBucketIntelligentTieringConfiguration
  • putBucketInventoryConfiguration
  • putBucketLifecycleConfiguration
  • putBucketLogging
  • putBucketMetricsConfiguration
  • putBucketNotificationConfiguration
  • putBucketOwnershipControls
  • putBucketPolicy
  • putBucketReplication
  • putBucketRequestPayment
  • putBucketTagging
  • putBucketVersioning
  • putBucketWebsite
  • putObjectAcl
  • putObjectLegalHold
  • putObjectLockConfiguration
  • putObjectRetention
  • putObjectTagging
  • putPublicAccessBlock
  • restoreObject
  • selectObjectContent
  • send
  • uploadPart
  • uploadPartCopy
  • writeGetObjectResponse
  • AbortMultipartUploadCommand
  • CompleteMultipartUploadCommand
  • CreateMultipartUploadCommand
  • DeleteBucketAnalyticsConfigurationCommand
  • DeleteBucketCorsCommand
  • DeleteBucketEncryptionCommand
  • DeleteBucketIntelligentTieringConfigurationCommand
  • DeleteBucketInventoryConfigurationCommand
  • DeleteBucketLifecycleCommand
  • DeleteBucketMetricsConfigurationCommand
  • DeleteBucketOwnershipControlsCommand
  • DeleteBucketPolicyCommand
  • DeleteBucketReplicationCommand
  • DeleteBucketTaggingCommand
  • GetBucketAccelerateConfigurationCommand
  • GetBucketAclCommand
  • DeleteBucketWebsiteCommand
  • DeleteObjectTaggingCommand
  • DeletePublicAccessBlockCommand
  • GetBucketAnalyticsConfigurationCommand
  • GetBucketCorsCommand
  • GetBucketEncryptionCommand
  • GetBucketIntelligentTieringConfigurationCommand
  • GetBucketInventoryConfigurationCommand
  • GetBucketLifecycleConfigurationCommand
  • GetBucketLocationCommand
  • GetBucketLoggingCommand
  • GetBucketMetricsConfigurationCommand
  • GetBucketNotificationConfigurationCommand
  • GetBucketOwnershipControlsCommand
  • GetBucketPolicyCommand
  • GetBucketPolicyStatusCommand
  • GetBucketReplicationCommand
  • GetBucketRequestPaymentCommand
  • GetBucketTaggingCommand
  • GetBucketVersioningCommand
  • GetBucketWebsiteCommand
  • GetObjectAclCommand
  • GetObjectLegalHoldCommand
  • GetObjectLockConfigurationCommand
  • GetObjectRetentionCommand
  • GetObjectTaggingCommand
  • GetPublicAccessBlockCommand
  • HeadBucketCommand
  • HeadObjectCommand
  • ListBucketAnalyticsConfigurationsCommand
  • ListBucketIntelligentTieringConfigurationsCommand
  • ListBucketInventoryConfigurationsCommand
  • ListBucketMetricsConfigurationsCommand
  • ListMultipartUploadsCommand
  • ListObjectVersionsCommand
  • ListPartsCommand
  • PutBucketAccelerateConfigurationCommand
  • PutBucketAclCommand
  • PutBucketAnalyticsConfigurationCommand
  • PutBucketCorsCommand
  • PutBucketEncryptionCommand
  • PutBucketIntelligentTieringConfigurationCommand
  • PutBucketInventoryConfigurationCommand
  • PutBucketLifecycleConfigurationCommand
  • PutBucketLoggingCommand
  • PutBucketMetricsConfigurationCommand
  • PutBucketNotificationConfigurationCommand
  • PutBucketOwnershipControlsCommand
  • PutBucketPolicyCommand
  • PutBucketReplicationCommand
  • PutBucketRequestPaymentCommand
  • PutBucketTaggingCommand
  • PutBucketVersioningCommand
  • PutBucketWebsiteCommand
  • PutObjectAclCommand
  • PutObjectLegalHoldCommand
  • PutObjectLockConfigurationCommand
  • PutObjectRetentionCommand
  • PutObjectTaggingCommand
  • PutPublicAccessBlockCommand
  • UploadPartCommand
  • UploadPartCopyCommand
  • WriteGetObjectResponseCommand
useInsertLink
  • putObject
  • copyObject
  • putObject
  • copyObject
  • RestoreObjectCommand
  • PutObjectCommand
  • CopyObjectCommand
useDeleteLink
  • deleteBucket
  • deleteObject

  • deleteObjects

  • deleteBucket
  • deleteObject

  • deleteObjects

  • DeleteBucketCommand
  • DeleteObjectCommand
  • DeleteObjectsCommand
useSelectLink
  • getObject
  • getObjectTorrent
  • listObjects

  • listObjectsV2

  • copyObject
  • getObject
  • getObjectTorrent
  • listObjects
  • listObjectsV2
  • copyObject
  • GetObjectCommand
  • ListObjectsCommand
  • ListObjectsV2Command
  • SelectObjectContentCommand
  • GetObjectTorrentCommand
  • CopyObjectCommand
useUpdateLink
  • putBucketAnalyticsConfiguration
  • putBucketAnalyticsConfiguration
  • RestoreObjectCommand
  • PutObjectCommand
  • CopyObjectCommand

Examples

This code will create a S3 Bucket named “BucketTest1” on an AWS server:

//import  { SNSClient } from "@aws-sdk/client-sns";
// ES5 example
const {S3Client} = require("@aws-sdk/client-s3");
// Set the AWS Region.
const REGION = "us-east-1";
// Create an Amazon S3 service client object.
const s3Client = new S3Client({ region: REGION });
export { s3Client };

const {CreateBucketCommand} = require("@aws-sdk/client-s3");

const {PutObjectCommand} = require("@aws-sdk/client-s3");

const {DeleteBucketCommand} = require("@aws-sdk/client-s3");

import {path} from "path";
import {fs} from "fs";

const file = "OBJECT_PATH_AND_NAME"; // Path to and name of object. For example '../myFiles/index.js'.
const fileStream = fs.createReadStream(file);

export const bucket = {
  Bucket: "BucketTest1",
  ACL : "public-read'"
};

// Create the Amazon S3 bucket.
export const runTest = async () => {
  try {
    const data = await s3Client.send(new CreateBucketCommand(bucket));
    console.log("Success", data);
    return data; // For unit tests.
  } catch (err) {
    console.log("Error", err);
  }
};
runTest();

export const uploadParams = {
  Bucket: "BucketTest1",
  // Add the required 'Key' parameter using the 'path' module.
  Key: path.basename(file),
  // Add the required 'Body' parameter
  Body: fileStream,
};

// Upload file to specified bucket.
export const runTestPut = async () => {
  try {
    const data = await s3Client.send(new PutObjectCommand(uploadParams));
    console.log("Success", data);
    return data; // For unit tests.
  } catch (err) {
    console.log("Error", err);
  }
};
runTestPut();

// Upload file to specified bucket.
export const runTestDelete = async () => {
  try {
    const data = await s3Client.send(new DeleteBucketCommand(bucket));
    console.log("Success", data);
    return data; // For unit tests.
  } catch (err) {
    console.log("Error", err);
  }
};
runTestDelete();

The code listed above will produce the following results:

Limitations

  • Use of access points is not supported.