How to use the S3 function from aws-sdk

Find comprehensive JavaScript aws-sdk.S3 code examples handpicked from public code repositorys.

AWS SDK S3 is a JavaScript library that provides a simple interface for interacting with Amazon S3 (Simple Storage Service), allowing developers to store and retrieve data from an S3 bucket.

31
32
33
34
35
36
37
38
39
40
    });
}

if (!s3) {
    // create an S3 client for the region to hand to the in-place copy processor
    s3 = new aws.S3({
        apiVersion: '2006-03-01',
        region: setRegion
    });
}
fork icon171
star icon593
watch icon50

+ 8 other calls in file

1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
  WorkspaceId: workspaceId,
  CourseId: courseId,
  InstitutionId: institutionId,
};

const s3 = new AWS.S3({ maxRetries: 3 });
await s3
  .putObject({
    Bucket: config.workspaceLogsS3Bucket,
    Key: key,
fork icon252
star icon248
watch icon14

+ 24 other calls in file

How does aws-sdk.S3 work?

The AWS SDK for JavaScript provides a high-level client for interacting with Amazon S3, which allows users to store and retrieve any amount of data from anywhere on the web. It supports a wide range of features including object storage, bucket creation, access control, server-side encryption, versioning, and lifecycle policies.

876
877
878
879
880
881
882
883
884
885
886
887
  }


  console.info('Finished cardbase update...');
};


const s3 = new AWS.S3({
  accessKeyId: process.env.AWS_ACCESS_KEY,
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
});

fork icon99
star icon159
watch icon9

+ 27 other calls in file

1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
        Policy: JSON.stringify(policy)
    }).promise();
}


function generate_s3_client(access_key, secret_key) {
    return new AWS.S3({
        s3ForcePathStyle: true,
        signatureVersion: 'v4',
        computeChecksums: true,
        s3DisableBodySigning: false,
fork icon68
star icon228
watch icon17

+ 6 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const AWS = require("aws-sdk");
const fs = require("fs");

// configure the AWS SDK with your access keys and region
AWS.config.update({
  accessKeyId: "your-access-key-id",
  secretAccessKey: "your-secret-access-key",
  region: "your-aws-region",
});

// create a new instance of the S3 class
const s3 = new AWS.S3();

// specify the parameters for the S3 object you want to create
const params = {
  Bucket: "your-bucket-name",
  Key: "path/to/new-object",
  Body: fs.readFileSync("path/to/local/file"),
};

// use the S3 instance to upload the object to S3
s3.upload(params, function (err, data) {
  if (err) {
    console.log("Error uploading file:", err);
  } else {
    console.log("File uploaded successfully:", data.Location);
  }
});

This example uses the upload method of the S3 class to upload a file to an S3 bucket. It specifies the bucket name, the key (i.e. the path and filename) of the new object in the bucket, and the contents of the file to be uploaded. Once the upload is complete, it logs either an error message or the URL of the newly uploaded file.

56
57
58
59
60
61
62
63
64
65
66
        creds.Credentials.SessionToken
    );
}


function get_signed_url(params) {
    let s3 = new AWS.S3({
        endpoint: params.endpoint,
        credentials: {
            accessKeyId: params.access_key.unwrap(),
            secretAccessKey: params.secret_key.unwrap()
fork icon68
star icon227
watch icon17

+ 113 other calls in file

762
763
764
765
766
767
768
769
770
771
    }
}

/** 
 * @param {Partial<{
 *   ServerSideEncryption: AWS.S3.ServerSideEncryption,
 *   SSEKMSKeyId: AWS.S3.SSEKMSKeyId,
 *   SSECustomerKey: AWS.S3.SSECustomerKey,
 *   SSECustomerAlgorithm: AWS.S3.SSECustomerAlgorithm,
 *   CopySourceSSECustomerKey: AWS.S3.CopySourceSSECustomerKey,
fork icon68
star icon227
watch icon17

+ 531 other calls in file

17
18
19
20
21
22
23
24
25
26
27
class NamespaceS3 {


    /**
     * @param {{
     *      namespace_resource_id: any,
     *      s3_params: AWS.S3.ClientConfiguration & {
     *          access_mode?: string,
     *          aws_sts_arn?: string,
     *      },
     *      stats: import('./endpoint_stats_collector').EndpointStatsCollector,
fork icon68
star icon226
watch icon17

+ 344 other calls in file

1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
    connection.sessionToken = creds.sessionToken;
} else {
    access_key = connection.access_key.unwrap();
    secret_key = connection.secret_key.unwrap();
}
var s3 = new AWS.S3({
    endpoint: connection.endpoint,
    accessKeyId: access_key,
    secretAccessKey: secret_key,
    sessionToken: connection.sessionToken,
fork icon68
star icon225
watch icon17

+ 50 other calls in file

18
19
20
21
22
23
24
25
26
27

const httpClient = new aws.NodeHttpClient();
const httpAgent = httpClient.getAgent(true, {
  keepAlive: false,
});
this.client = new aws.S3({
  httpOptions: {
    agent: httpAgent,
  },
});
fork icon50
star icon139
watch icon0

+ 2 other calls in file

37
38
39
40
41
42
43
44
45
46
47
48
49


const convertDocxSurveyToJson = require('../active-citizen/engine/analytics/manager').convertDocxSurveyToJson;


const copyGroup = require('../utils/copy_utils.js').copyGroup;


var s3 = new aws.S3({
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
  accessKeyId: process.env.AWS_ACCESS_KEY_ID,
  endpoint: process.env.S3_ENDPOINT || null,
  acl: 'public-read',
fork icon35
star icon108
watch icon0

+ 3 other calls in file

-4
fork icon34
star icon97
watch icon41

+ 9 other calls in file

7
8
9
10
11
12
13
14
15
16
const crypto = require('crypto');
const { exec, fork } = require('child_process');

const region = 'us-east-1';

const s3 = new aws.S3({ region });
const ddb = new aws.DynamoDB({ region });
const meta = new aws.MetadataService();

class WARCannon {
fork icon31
star icon212
watch icon3

35
36
37
38
39
40
41
42
43
44
45
  domain: 'telus-design-system-docs',
  uploadDir,
  lockConfig: true,
  exclude: ['community/*'],
}
const s3 = new AWS.S3({ region: config.region })


const deployToS3 = prefix =>
  new Promise((resolve, reject) => {
    const deployConfig = Object.assign(config, { prefix })
fork icon50
star icon93
watch icon127

+ 46 other calls in file

5
6
7
8
9
10
11
12
13
const browser = require('./browser')

const cwEvents = new AWS.CloudWatchEvents({
  endpoint: process.env.CLOUDWATCH_ENDPOINT_URL
})
const s3 = new AWS.S3({ endpoint: process.env.S3_ENDPOINT_URL })
const ssm = new AWS.SSM({ endpoint: process.env.SSM_ENDPOINT_URL })

const log = require('./log')
fork icon21
star icon48
watch icon8

26
27
28
29
30
31
32
33
34
35

  this.s3 = new AWS.S3();
}

/**
 * AWS.S3.listBuckets wrapper.
 * @returns {Promise}
 */
getBuckets() {
  return new Promise((resolve, reject) => {
fork icon14
star icon134
watch icon5

+ 5 other calls in file

71
72
73
74
75
76
77
78
79
80
81
	fileStream.on('error', function (err) {
		Log.error('File Error', err);
	});
	const keyName = 'regional/' + filename;
	const objectParams = { Bucket: bucketName, Key: keyName, Body: fileStream };
	const res = await new aws.S3({ apiVersion: '2006-03-01' }).putObject(objectParams).promise();
	Log.info(`Successfully Uploaded to ${bucketName}/${keyName}. Status code: ${res.$response.httpResponse.statusCode}`);
}


async function generateGeom(db, place, street, home_number, gush, helka) {
fork icon20
star icon49
watch icon20

41
42
43
44
45
46
47
48
49

Here is an example function that maybe you would like to test.

```js
const getThing = async () => {
  const s3 = new AWS.S3({ region: 'us-east-1' });
  return await s3.getObject({ Bucket: 'my', Key: 'thing' }).promise();
};
```
fork icon3
star icon19
watch icon79

+ 3 other calls in file

7
8
9
10
11
12
13
14
15
16
  return await s3.getObject({ Bucket: 'my', Key: 'thing' }).promise();
};

const eachPager = () =>
  new Promise((resolve, reject) => {
    const s3 = new AWS.S3({ region: 'ab-cdef-1' });
    let things = [];
    s3.listObjectsV2({ Bucket: 'my' }).eachPage((err, data, done) => {
      if (err) return reject(err);
      if (!data) return resolve(things);
fork icon3
star icon19
watch icon79

+ 19 other calls in file

28
29
30
31
32
33
34
35
36
37
    }
    resolve()
  }))
} else {
  state = {
    s3: new AWS.S3({
      endpoint: process.env.S3_ENDPOINT,
      s3ForcePathStyle: process.env.S3_FORCE_PATH_STYLE
    }),
    Bucket: process.env.S3_BUCKET
fork icon32
star icon214
watch icon13

+ 99 other calls in file

167
168
169
170
171
172
173
174
175
176
});

it('should log error when encountered and not reject', () => {
    const context = testUtil.buildConsumerContext(defaultConsumerConfig);
    const error = new Error('simulated error');
    AWS.S3.restore();
    sinon.stub(AWS, 'S3').returns({
        putObject: (params, cb) => {
            s3PutObjectParams = params;
            cb(error, '');
fork icon23
star icon49
watch icon20

+ 19 other calls in file