Skip to content

Commit b2a13cf

Browse files
authored
Merge pull request #1168 from grafana/jslib-aws/v0.8.0
[WIP] Add documentation for changes introduced by jslib-aws v0.8.0
2 parents 374412c + 07a108d commit b2a13cf

38 files changed

+513
-39
lines changed

.vale/Vocab/docs/accept.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Dynatrace
6868
enum
6969
errno
7070
erroring
71+
etag
7172
falsy
7273
flatlined
7374
fn

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import exec from 'k6/execution';
4141

4242
// Note that you AWSConfig is also included in the dedicated service
4343
// client bundles such as `s3.js` and `secrets-manager.js`
44-
import { AWSConfig, SecretsManagerClient } from 'https://jslib.k6.io/aws/0.7.2/aws.js';
44+
import { AWSConfig, SecretsManagerClient } from 'https://jslib.k6.io/aws/0.8.0/aws.js';
4545

4646
const awsConfig = new AWSConfig({
4747
region: __ENV.AWS_REGION,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Both the dedicated `kms.js` jslib bundle and the all-encompassing `aws.js` bundl
3535
```javascript
3636
import { textSummary } from 'https://jslib.k6.io/k6-summary/0.0.2/index.js';
3737

38-
import { AWSConfig, KMSClient } from 'https://jslib.k6.io/aws/0.7.2/kms.js';
38+
import { AWSConfig, KMSClient } from 'https://jslib.k6.io/aws/0.8.0/kms.js';
3939

4040
const awsConfig = new AWSConfig({
4141
region: __ENV.AWS_REGION,

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

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ 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 |
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 |
2327

2428
### Throws
2529

@@ -30,7 +34,7 @@ S3 Client methods will throw errors in case of failure.
3034
| InvalidSignatureError | when invalid credentials were provided. |
3135
| S3ServiceError | when AWS replied to the requested operation with an error. |
3236

33-
### Example
37+
### Examples
3438

3539
<CodeGroup labels={[]}>
3640

@@ -39,7 +43,7 @@ import { check } from 'k6';
3943
import exec from 'k6/execution';
4044
import http from 'k6/http';
4145

42-
import { AWSConfig, S3Client } from 'https://jslib.k6.io/aws/0.7.2/s3.js';
46+
import { AWSConfig, S3Client } from 'https://jslib.k6.io/aws/0.8.0/s3.js';
4347

4448
const awsConfig = new AWSConfig({
4549
region: __ENV.AWS_REGION,
@@ -92,3 +96,75 @@ export function handleSummary(data) {
9296
```
9397

9498
</CodeGroup>
99+
100+
<CodeGroup labels={[]}>
101+
102+
```javascript
103+
import crypto from 'k6/crypto';
104+
import exec from 'k6/execution';
105+
106+
import { AWSConfig, S3Client } from 'https://jslib.k6.io/aws/0.8.0/s3.js';
107+
108+
const awsConfig = new AWSConfig({
109+
region: __ENV.AWS_REGION,
110+
accessKeyId: __ENV.AWS_ACCESS_KEY_ID,
111+
secretAccessKey: __ENV.AWS_SECRET_ACCESS_KEY,
112+
sessionToken: __ENV.AWS_SESSION_TOKEN,
113+
});
114+
115+
const s3 = new S3Client(awsConfig);
116+
117+
const testBucketName = 'test-jslib-aws';
118+
const testFileKey = 'multipart.txt';
119+
120+
export default function () {
121+
// List the buckets the AWS authentication configuration
122+
// gives us access to.
123+
const buckets = s3.listBuckets();
124+
125+
// If our test bucket does not exist, abort the execution.
126+
if (buckets.filter((b) => b.name === testBucketName).length == 0) {
127+
exec.test.abort();
128+
}
129+
130+
// Produce random bytes to upload of size ~12MB, that
131+
// we will upload in two 6MB parts. This is done as the
132+
// minimum part size supported by S3 is 5MB.
133+
const bigFile = crypto.randomBytes(12 * 1024 * 1024);
134+
135+
// Initialize a multipart upload
136+
const multipartUpload = s3.createMultipartUpload(testBucketName, testFileKey);
137+
138+
// Upload the first part
139+
const firstPartData = bigFile.slice(0, 6 * 1024 * 1024);
140+
const firstPart = s3.uploadPart(
141+
testBucketName,
142+
testFileKey,
143+
multipartUpload.uploadId,
144+
1,
145+
firstPartData
146+
);
147+
148+
// Upload the second part
149+
const secondPartData = bigFile.slice(6 * 1024 * 1024, 12 * 1024 * 1024);
150+
const secondPart = s3.uploadPart(
151+
testBucketName,
152+
testFileKey,
153+
multipartUpload.uploadId,
154+
2,
155+
secondPartData
156+
);
157+
158+
// Complete the multipart upload
159+
s3.completeMultipartUpload(testBucketName, testFileKey, multipartUpload.uploadId, [
160+
firstPart,
161+
secondPart,
162+
]);
163+
164+
// Let's redownload it verify it's correct, and delete it
165+
const obj = s3.getObject(testBucketName, testFileKey);
166+
s3.deleteObject(testBucketName, testFileKey);
167+
}
168+
```
169+
170+
</CodeGroup>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Both the dedicated `sqs.js` jslib bundle and the all-encompassing `aws.js` bundl
3434
```javascript
3535
import exec from 'k6/execution'
3636

37-
import { AWSConfig, SQSClient } from 'https://jslib.k6.io/aws/0.7.2/sqs.js'
37+
import { AWSConfig, SQSClient } from 'https://jslib.k6.io/aws/0.8.0/sqs.js'
3838

3939
const awsConfig = new AWSConfig({
4040
region: __ENV.AWS_REGION,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ S3 Client methods will throw errors in case of failure.
3737
```javascript
3838
import exec from 'k6/execution';
3939

40-
import { AWSConfig, SecretsManagerClient } from 'https://jslib.k6.io/aws/0.7.2/secrets-manager.js';
40+
import { AWSConfig, SecretsManagerClient } from 'https://jslib.k6.io/aws/0.8.0/secrets-manager.js';
4141

4242
const awsConfig = new AWSConfig({
4343
region: __ENV.AWS_REGION,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ SignatureV4 methods throw errors on failure.
4444
```javascript
4545
import http from 'k6/http.js'
4646

47-
import { AWSConfig, SignatureV4 } from 'https://jslib.k6.io/aws/0.7.2/aws.js'
47+
import { AWSConfig, SignatureV4 } from 'https://jslib.k6.io/aws/0.8.0/aws.js'
4848

4949
const awsConfig = new AWSConfig({
5050
region: __ENV.AWS_REGION,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Both the dedicated `ssm.js` jslib bundle and the all-encompassing `aws.js` bundl
3434
```javascript
3535
import exec from 'k6/execution';
3636

37-
import { AWSConfig, SystemsManagerClient } from 'https://jslib.k6.io/aws/0.7.2/ssm.js';
37+
import { AWSConfig, SystemsManagerClient } from 'https://jslib.k6.io/aws/0.8.0/ssm.js';
3838

3939
const awsConfig = new AWSConfig({
4040
region: __ENV.AWS_REGION,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ excerpt: 'KMSClient.generateDataKey generates a symmetric data key for use outsi
2626
```javascript
2727
import exec from 'k6/execution';
2828

29-
import { AWSConfig, KMSClient } from 'https://jslib.k6.io/aws/0.7.2/kms.js';
29+
import { AWSConfig, KMSClient } from 'https://jslib.k6.io/aws/0.8.0/kms.js';
3030

3131
const awsConfig = new AWSConfig({
3232
region: __ENV.AWS_REGION,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ excerpt: "KMSClient.listKeys lists all the KMS keys in the caller's AWS account
1919
```javascript
2020
import exec from 'k6/execution';
2121

22-
import { AWSConfig, KMSClient } from 'https://jslib.k6.io/aws/0.7.2/kms.js';
22+
import { AWSConfig, KMSClient } from 'https://jslib.k6.io/aws/0.8.0/kms.js';
2323

2424
const awsConfig = new AWSConfig({
2525
region: __ENV.AWS_REGION,

0 commit comments

Comments
 (0)