Skip to content

Commit 54825f8

Browse files
committed
Add jslib-aws s3.copyObject operation's documentation
1 parent 0d90124 commit 54825f8

File tree

2 files changed

+63
-11
lines changed

2 files changed

+63
-11
lines changed

src/data/markdown/docs/20 jslib/01 jslib/01 aws/00 S3Client.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ S3Client is included in both the dedicated jslib `s3.js` bundle, and the `aws.js
1313

1414
### Methods
1515

16-
| Function | Description |
17-
| :------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------|
18-
| [listBuckets()](/javascript-api/jslib/aws/s3client/s3client-listbuckets) | List the buckets the authenticated user has access to |
19-
| [listObjects(bucketName, [prefix])](/javascript-api/jslib/aws/s3client/s3client-listobjects/) | List the objects contained in a bucket |
20-
| [getObject(bucketName, objectKey)](/javascript-api/jslib/aws/s3client/s3client-getobject/) | Download an object from a bucket |
21-
| [putObject(bucketName, objectKey, data)](/javascript-api/jslib/aws/s3client/s3client-putobject/) | Upload an object to a bucket |
22-
| [deleteObject(bucketName, objectKey)](/javascript-api/jslib/aws/s3client/s3client-deleteobject/) | Delete an object from a bucket |
23-
| [createMultipartUpload(bucketName, objectKey)](/javascript-api/jslib/aws/s3client/s3client-createmultipartupload/) | Create a multipart upload for a given objectKey to a bucket |
24-
| [uploadPart(bucketName, objectKey, uploadId, partNumber, data)](/javascript-api/jslib/aws/s3client/s3client-uploadpart/) | Upload a part in a multipart upload |
25-
| [completeMultipartUpload(bucketName, objectKey, uploadId, parts)](/javascript-api/jslib/aws/s3client/s3client-completemultipartupload/) | Complete a previously assembled multipart upload |
26-
| [abortMultipartUpload(bucketName, objectKey, uploadId)](/javascript-api/jslib/aws/s3client/s3client-abortmultipartupload/) | Abort a multipart upload |
16+
| Function | Description |
17+
| :-------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------- |
18+
| [listBuckets()](/javascript-api/jslib/aws/s3client/s3client-listbuckets) | List the buckets the authenticated user has access to |
19+
| [listObjects(bucketName, [prefix])](/javascript-api/jslib/aws/s3client/s3client-listobjects/) | List the objects contained in a bucket |
20+
| [getObject(bucketName, objectKey)](/javascript-api/jslib/aws/s3client/s3client-getobject/) | Download an object from a bucket |
21+
| [putObject(bucketName, objectKey, data)](/javascript-api/jslib/aws/s3client/s3client-putobject/) | Upload an object to a bucket |
22+
| [deleteObject(bucketName, objectKey)](/javascript-api/jslib/aws/s3client/s3client-deleteobject/) | Delete an object from a bucket |
23+
| [copyObject(sourceBucket, sourceKey, destinationBucket, destinationKey)](/javascript-api/jslib/aws/s3client/s3client-copyobject/) | Copy an object from one bucket to another |
24+
| [createMultipartUpload(bucketName, objectKey)](/javascript-api/jslib/aws/s3client/s3client-createmultipartupload/) | Create a multipart upload for a given objectKey to a bucket |
25+
| [uploadPart(bucketName, objectKey, uploadId, partNumber, data)](/javascript-api/jslib/aws/s3client/s3client-uploadpart/) | Upload a part in a multipart upload |
26+
| [completeMultipartUpload(bucketName, objectKey, uploadId, parts)](/javascript-api/jslib/aws/s3client/s3client-completemultipartupload/) | Complete a previously assembled multipart upload |
27+
| [abortMultipartUpload(bucketName, objectKey, uploadId)](/javascript-api/jslib/aws/s3client/s3client-abortmultipartupload/) | Abort a multipart upload |
2728

2829
### Throws
2930

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: 'S3Client.copyObject'
3+
description: 'S3Client.copyObject copies an object from a bucket to another'
4+
excerpt: 'S3Client.copyObject copies an object from a bucket to another'
5+
---
6+
7+
`S3Client.copyObject` copies an object from one bucket to another.
8+
9+
### Parameters
10+
11+
| Parameter | Type | Description |
12+
| :---------------- | :----- | :------------------------------------------------- |
13+
| sourceBucket | string | Name of the bucket to copy the object from. |
14+
| sourceKey | string | Name of the object to copy from the source bucket. |
15+
| destinationBucket | string | Name of the bucket to copy the object to. |
16+
| destinationKey | string | Name of the destination object. |
17+
18+
### Example
19+
20+
<CodeGroup labels={[]}>
21+
22+
```javascript
23+
import exec from 'k6/execution';
24+
25+
import { AWSConfig, S3Client } from 'https://jslib.k6.io/aws/0.8.1/s3.js';
26+
27+
28+
const awsConfig = new AWSConfig({
29+
region: __ENV.AWS_REGION,
30+
accessKeyId: __ENV.AWS_ACCESS_KEY_ID,
31+
secretAccessKey: __ENV.AWS_SECRET_ACCESS_KEY,
32+
});
33+
34+
const testFile = open('./bonjour.txt', 'r');
35+
const s3 = new S3Client(awsConfig);
36+
const testBucketName = 'test-jslib-aws';
37+
const testFileKey = 'bonjour.txt';
38+
const testDestinationBucketName = 'test-jslib-aws-destination';
39+
40+
export default function () {
41+
// Let's upload our test file to the bucket
42+
s3.putObject(testBucketName, testFileKey, testFile);
43+
44+
// Let's create our destination bucket
45+
s3.copyObject(testBucketName, testFileKey, testDestinationBucketName, testFileKey);
46+
}
47+
```
48+
49+
_A k6 script that will copy an object from a source S3 bucket to a destination bucket_
50+
51+
</CodeGroup>

0 commit comments

Comments
 (0)