Skip to content

Commit 8a92d06

Browse files
committed
docs(aws): add k6-jslib-aws v0.14.0 SQS and S3 enhancements
- Add receiveMessages and deleteMessage methods for complete SQS message lifecycle - Update SQS documentation to include all available methods in methods table - Add S3UploadedObject type documentation for enhanced upload response data - Update putObject and completeMultipartUpload to return S3UploadedObject with checksums - Fix documentation formatting: remove backticks from parameter names and Promise types - Enhance examples to demonstrate practical usage of new features
1 parent f93ec2a commit 8a92d06

File tree

9 files changed

+400
-66
lines changed

9 files changed

+400
-66
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
---
2+
title: 'S3UploadedObject'
3+
head_title: 'S3UploadedObject'
4+
description: 'S3UploadedObject represents the response from S3 upload operations'
5+
weight: 20
6+
---
7+
8+
# S3UploadedObject
9+
10+
`S3UploadedObject` represents the response returned by S3 upload operations such as [`putObject`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/aws/s3client/putobject) and [`completeMultipartUpload`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/aws/s3client/completemultipartupload). It contains metadata about the uploaded object, including checksums and upload verification information.
11+
12+
## Properties
13+
14+
| Name | Type | Description |
15+
| :----------- | :---------------- | :---------------------------------------------------------------------------------------------------------------------------------------- |
16+
| eTag | string | The entity tag (ETag) of the uploaded object. This is a hash of the object that can be used to verify the integrity of the uploaded data. |
17+
| crc32 | string (optional) | The base64-encoded CRC32 checksum of the uploaded object, if available. |
18+
| crc32c | string (optional) | The base64-encoded CRC32C checksum of the uploaded object, if available. |
19+
| crc64nvme | string (optional) | The base64-encoded CRC64NVME checksum of the uploaded object, if available. |
20+
| sha1 | string (optional) | The base64-encoded SHA1 checksum of the uploaded object, if available. |
21+
| sha256 | string (optional) | The base64-encoded SHA256 checksum of the uploaded object, if available. |
22+
| checksumType | string (optional) | The type of checksum algorithm used. Can be "COMPOSITE" for multipart uploads or "FULL_OBJECT" for single-part uploads. |
23+
| size | number (optional) | The size of the uploaded object in bytes, if available. |
24+
25+
## Example
26+
27+
{{< code >}}
28+
29+
```javascript
30+
import {
31+
AWSConfig,
32+
S3Client,
33+
} from 'https://jslib.k6.io/aws/{{< param "JSLIB_AWS_VERSION" >}}/s3.js';
34+
35+
const awsConfig = new AWSConfig({
36+
region: __ENV.AWS_REGION,
37+
accessKeyId: __ENV.AWS_ACCESS_KEY_ID,
38+
secretAccessKey: __ENV.AWS_SECRET_ACCESS_KEY,
39+
});
40+
41+
const s3 = new S3Client(awsConfig);
42+
const testBucketName = 'test-jslib-aws';
43+
const testFileKey = 'test-file.txt';
44+
45+
export default async function () {
46+
const testData = 'Hello, World!';
47+
48+
// Upload the object and get the upload response
49+
const uploadResult = await s3.putObject(testBucketName, testFileKey, testData);
50+
51+
// Access the upload metadata
52+
console.log('Upload ETag:', uploadResult.eTag);
53+
console.log('Object size:', uploadResult.size);
54+
55+
// Check if checksums are available
56+
if (uploadResult.sha256) {
57+
console.log('SHA256 checksum:', uploadResult.sha256);
58+
}
59+
60+
if (uploadResult.checksumType) {
61+
console.log('Checksum type:', uploadResult.checksumType);
62+
}
63+
64+
// Verify the upload was successful
65+
if (uploadResult.eTag) {
66+
console.log('Upload successful, ETag received:', uploadResult.eTag);
67+
}
68+
}
69+
```
70+
71+
{{< /code >}}
72+
73+
## Usage in Multipart Uploads
74+
75+
For multipart uploads, the `S3UploadedObject` is returned by the `completeMultipartUpload` method:
76+
77+
{{< code >}}
78+
79+
```javascript
80+
import crypto from 'k6/crypto';
81+
import {
82+
AWSConfig,
83+
S3Client,
84+
} from 'https://jslib.k6.io/aws/{{< param "JSLIB_AWS_VERSION" >}}/s3.js';
85+
86+
const awsConfig = new AWSConfig({
87+
region: __ENV.AWS_REGION,
88+
accessKeyId: __ENV.AWS_ACCESS_KEY_ID,
89+
secretAccessKey: __ENV.AWS_SECRET_ACCESS_KEY,
90+
});
91+
92+
const s3 = new S3Client(awsConfig);
93+
94+
export default async function () {
95+
const testBucketName = 'test-jslib-aws';
96+
const testFileKey = 'large-file.txt';
97+
98+
// Create large file data
99+
const bigFile = crypto.randomBytes(12 * 1024 * 1024); // 12MB
100+
101+
// Initialize multipart upload
102+
const multipartUpload = await s3.createMultipartUpload(testBucketName, testFileKey);
103+
104+
// Upload parts
105+
const firstPart = await s3.uploadPart(
106+
testBucketName,
107+
testFileKey,
108+
multipartUpload.uploadId,
109+
1,
110+
bigFile.slice(0, 6 * 1024 * 1024)
111+
);
112+
113+
const secondPart = await s3.uploadPart(
114+
testBucketName,
115+
testFileKey,
116+
multipartUpload.uploadId,
117+
2,
118+
bigFile.slice(6 * 1024 * 1024)
119+
);
120+
121+
// Complete the multipart upload and get the result
122+
const uploadResult = await s3.completeMultipartUpload(
123+
testBucketName,
124+
testFileKey,
125+
multipartUpload.uploadId,
126+
[firstPart, secondPart]
127+
);
128+
129+
// Access the completed upload metadata
130+
console.log('Multipart upload ETag:', uploadResult.eTag);
131+
console.log('Checksum type:', uploadResult.checksumType); // Likely "COMPOSITE"
132+
133+
if (uploadResult.size) {
134+
console.log('Total object size:', uploadResult.size);
135+
}
136+
}
137+
```
138+
139+
{{< /code >}}

docs/sources/k6/next/javascript-api/jslib/aws/S3Client/completeMultipartUpload.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ weight: 10
2020

2121
### Returns
2222

23-
| Type | Description |
24-
| :-------------- | :-------------------------------------------------------------------- |
25-
| `Promise<void>` | A Promise that fulfills when the multipart upload has been completed. |
23+
| Type | Description |
24+
| :----------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
25+
| Promise<[S3UploadedObject](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/aws/s3client/s3uploadedobject)> | A Promise that fulfills with an [S3UploadedObject](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/aws/s3client/s3uploadedobject) containing metadata about the completed multipart upload, including ETag and optional checksums. |
2626

2727
### Example
2828

@@ -88,10 +88,24 @@ export default async function () {
8888
);
8989

9090
// Complete the multipart upload
91-
await s3.completeMultipartUpload(testBucketName, testFileKey, multipartUpload.uploadId, [
92-
firstPart,
93-
secondPart,
94-
]);
91+
const uploadResult = await s3.completeMultipartUpload(
92+
testBucketName,
93+
testFileKey,
94+
multipartUpload.uploadId,
95+
[firstPart, secondPart]
96+
);
97+
98+
// Access the upload metadata
99+
console.log('Multipart upload completed! ETag:', uploadResult.eTag);
100+
101+
if (uploadResult.size) {
102+
console.log('Total object size:', uploadResult.size);
103+
}
104+
105+
// For multipart uploads, the checksum type will typically be "COMPOSITE"
106+
if (uploadResult.checksumType) {
107+
console.log('Checksum type:', uploadResult.checksumType);
108+
}
95109

96110
// Let's redownload it verify it's correct, and delete it
97111
const obj = await s3.getObject(testBucketName, testFileKey);

docs/sources/k6/next/javascript-api/jslib/aws/S3Client/putObject.md

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,28 @@ weight: 10
1111

1212
### Parameters
1313

14-
| Parameter | Type | Description |
15-
| :----------- | :--------------------------------------------- | :------------------------------------------ |
16-
| `bucketName` | string | Name of the bucket to upload the object to. |
17-
| `objectKey` | string | Name of the uploaded object. |
18-
| `data` | string \| ArrayBuffer | Content of the object to upload. |
19-
| `params` | [PutObjectParams](#putobjectparams) (optional) | Options for the request. |
14+
| Parameter | Type | Description |
15+
| :--------- | :--------------------------------------------- | :------------------------------------------ |
16+
| bucketName | string | Name of the bucket to upload the object to. |
17+
| objectKey | string | Name of the uploaded object. |
18+
| data | string \| ArrayBuffer | Content of the object to upload. |
19+
| params | [PutObjectParams](#putobjectparams) (optional) | Options for the request. |
2020

2121
#### PutObjectParams
2222

23-
| Name | Type | Description |
24-
| :------------------- | :---------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
25-
| `contentDisposition` | string (optional) | Specifies presentational information for the object. For more information, see [RFC 6266](https://tools.ietf.org/html/rfc6266). |
26-
| `contentEncoding` | string (optional) | Specifies what content encodings have been applied to the object and thus what decoding mechanisms must be applied to obtain the media-type referenced by the Content-Type header field. For more information, see [RFC 2616](https://tools.ietf.org/html/rfc2616). |
27-
| `contentLength` | number (optional) | Size of the body in bytes. This parameter is useful when the size of the body cannot be determined automatically. |
28-
| `contentMD5` | string (optional) | The base64-encoded 128-bit MD5 digest of the message (without the headers) according to RFC 1864. This header can be used as a message integrity check to verify that the received message is identical to the message that was sent. |
29-
| `contentType` | string (optional) | A standard MIME type describing the format of the object data. For more information, see [RFC 2616](https://tools.ietf.org/html/rfc2616). |
23+
| Name | Type | Description |
24+
| :----------------- | :---------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
25+
| contentDisposition | string (optional) | Specifies presentational information for the object. For more information, see [RFC 6266](https://tools.ietf.org/html/rfc6266). |
26+
| contentEncoding | string (optional) | Specifies what content encodings have been applied to the object and thus what decoding mechanisms must be applied to obtain the media-type referenced by the Content-Type header field. For more information, see [RFC 2616](https://tools.ietf.org/html/rfc2616). |
27+
| contentLength | number (optional) | Size of the body in bytes. This parameter is useful when the size of the body cannot be determined automatically. |
28+
| contentMD5 | string (optional) | The base64-encoded 128-bit MD5 digest of the message (without the headers) according to RFC 1864. This header can be used as a message integrity check to verify that the received message is identical to the message that was sent. |
29+
| contentType | string (optional) | A standard MIME type describing the format of the object data. For more information, see [RFC 2616](https://tools.ietf.org/html/rfc2616). |
3030

3131
### Returns
3232

33-
| Type | Description |
34-
| :-------------- | :-------------------------------------------------------------------------- |
35-
| `Promise<void>` | A Promise that fulfills when the object has been uploaded to the S3 bucket. |
33+
| Type | Description |
34+
| :----------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
35+
| Promise<[S3UploadedObject](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/aws/s3client/s3uploadedobject)> | A Promise that fulfills with an [S3UploadedObject](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/aws/s3client/s3uploadedobject) containing metadata about the uploaded object, including ETag and optional checksums. |
3636

3737
### Example
3838

@@ -57,11 +57,23 @@ const testFile = open('./bonjour.txt', 'r');
5757

5858
export default async function () {
5959
// Let's upload our test file to the bucket
60-
await s3.putObject(testBucketName, testFileKey, testFile, {
60+
const uploadResult = await s3.putObject(testBucketName, testFileKey, testFile, {
6161
contentType: 'text/plain',
6262
contentLength: testFile.length,
6363
});
6464

65+
// Access the upload metadata
66+
console.log('Upload successful! ETag:', uploadResult.eTag);
67+
68+
if (uploadResult.size) {
69+
console.log('Object size:', uploadResult.size);
70+
}
71+
72+
// Check if checksums are available
73+
if (uploadResult.sha256) {
74+
console.log('SHA256 checksum:', uploadResult.sha256);
75+
}
76+
6577
// And let's redownload it to verify it's correct
6678
const obj = await s3.getObject(testBucketName, testFileKey);
6779
console.log(JSON.stringify(obj));

docs/sources/k6/next/javascript-api/jslib/aws/SQSClient/_index.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ weight: 00
1010

1111
`SQSClient` interacts with the AWS Simple Queue Service (SQS).
1212

13-
With it, the user can send messages to specified queues and list available queues in the current region.
13+
With it, the user can send messages to specified queues, receive messages from queues, delete processed messages, and list available queues in the current region.
1414

1515
`SQSClient` is included in both the dedicated `sqs.js` jslib bundle and the all-encompassing `aws.js` one, containing all the services clients.
1616

1717
### Methods
1818

19-
| Function | Description |
20-
| :------------------------------------------------------------------------------------------------------- | :--------------------------------------------------- |
21-
| [`sendMessage`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/aws/sqsclient/sendmessage) | Delivers a message to the specified queue. |
22-
| [`listQueues`](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/aws/sqsclient/listqueues) | Returns a list of your queues in the current region. |
19+
| Function | Description |
20+
| :--------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------- |
21+
| [sendMessage](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/aws/sqsclient/sendmessage) | Delivers a message to the specified queue. |
22+
| [sendMessageBatch](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/aws/sqsclient/sendmessagebatch) | Delivers up to ten messages to the specified queue. |
23+
| [receiveMessages](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/aws/sqsclient/receivemessages) | Receives messages from the specified queue. |
24+
| [deleteMessage](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/aws/sqsclient/deletemessage) | Deletes a message from the specified queue. |
25+
| [listQueues](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/jslib/aws/sqsclient/listqueues) | Returns a list of your queues in the current region. |
2326

2427
### Throws
2528

@@ -61,6 +64,20 @@ export default async function () {
6164

6265
// Send message to test queue
6366
await sqs.sendMessage(testQueue, JSON.stringify({ value: '123' }));
67+
68+
// Receive messages from the queue
69+
const messages = await sqs.receiveMessages(testQueue, {
70+
maxNumberOfMessages: 10,
71+
waitTimeSeconds: 2,
72+
});
73+
74+
// Process and delete each received message
75+
for (const message of messages) {
76+
console.log('Processing message:', message.body);
77+
78+
// Delete the message after processing
79+
await sqs.deleteMessage(testQueue, message.receiptHandle);
80+
}
6481
}
6582
```
6683

0 commit comments

Comments
 (0)