Skip to content

Commit 25052b9

Browse files
authored
Merge pull request #1276 from grafana/aws/v0.9.0
Update documentation to include changes in aws jslib v0.9.0
2 parents 376d2af + c85adc6 commit 25052b9

File tree

41 files changed

+284
-218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+284
-218
lines changed

src/components/shared/blocking-aws-blockquote/blocking-aws-blockquote.view.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@ const BlockingAwsBlockquote = () => (
66
mod="Attention"
77
title="Performance considerations and recommended practices"
88
>
9-
The APIs provided by this jslib operate synchronously, which means k6 must
10-
wait for operations that use the client classes to finish before proceeding
11-
with the rest of the script.
12-
<p>
13-
In some cases, such as downloading large files from S3, this could affect
14-
performance and test results. To minimize the impact on test performance,
15-
we recommend using these operations in the
16-
<span className="code-inline">setup</span> and{' '}
17-
<span className="code-inline">teardown</span>{' '}
18-
<a href="/docs/using-k6/test-lifecycle/">lifecycle functions</a>. These
19-
functions run before and after the test run and thus do not influence test
20-
results.
21-
</p>
9+
In some cases, using this library&apos;s operations might impact performance
10+
and skew your test results. <br />
11+
<br />
12+
To ensure accurate results, consider executing these operations in the{' '}
13+
<span className="code-inline">setup</span> and{' '}
14+
<span className="code-inline">teardown</span>{' '}
15+
<a href="/docs/using-k6/test-lifecycle/">lifecycle functions</a>. These
16+
functions run before and after the test run and have no impact on the test
17+
results.
2218
</Blockquote>
2319
);
2420

src/data/markdown/docs/05 Examples/01 Examples/02 http-authentication.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Here's an example script to demonstrate how to sign a request to fetch an object
118118

119119
```javascript
120120
import http from 'k6/http';
121-
import { AWSConfig, SignatureV4 } from 'https://jslib.k6.io/aws/0.8.1/signature.js';
121+
import { AWSConfig, SignatureV4 } from 'https://jslib.k6.io/aws/0.9.0/signature.js';
122122

123123
const awsConfig = new AWSConfig({
124124
region: __ENV.AWS_REGION,

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.8.1/aws.js';
44+
import { AWSConfig, SecretsManagerClient } from 'https://jslib.k6.io/aws/0.9.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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ excerpt: 'KMSClient allows interacting with the AWS Key Management Service'
88
<BlockingAwsBlockquote />
99

1010
`KMSClient` interacts with the AWS Key Management Service.
11-
With it, the user can list all the Key Management Service keys in the caller's AWS account and region. They can also generate symmetric data keys to use outside of AWS Key Management Service. `KMSClient` operations are blocking. k6 recommends reserving their use to the [`setup`](/using-k6/test-lifecycle/) and [`teardown`](/using-k6/test-lifecycle/) stages as much as possible.
11+
12+
With it, the user can list all the Key Management Service keys in the caller's AWS account and region. They can also generate symmetric data keys to use outside of AWS Key Management Service.
1213

1314
Both the dedicated `kms.js` jslib bundle and the all-encompassing `aws.js` bundle include the `KMSClient`.
1415

@@ -35,7 +36,7 @@ Both the dedicated `kms.js` jslib bundle and the all-encompassing `aws.js` bundl
3536
```javascript
3637
import { textSummary } from 'https://jslib.k6.io/k6-summary/0.0.2/index.js';
3738

38-
import { AWSConfig, KMSClient } from 'https://jslib.k6.io/aws/0.8.1/kms.js';
39+
import { AWSConfig, KMSClient } from 'https://jslib.k6.io/aws/0.9.0/kms.js';
3940

4041
const awsConfig = new AWSConfig({
4142
region: __ENV.AWS_REGION,
@@ -46,14 +47,14 @@ const awsConfig = new AWSConfig({
4647
const kms = new KMSClient(awsConfig);
4748
const keyAlias = 'alias/k6-key';
4849

49-
export function setup() {
50+
export async function setup() {
5051
// Create a symmetric data key
5152
return {
52-
dataKey: kms.generateDataKey(keyAlias, 32),
53+
dataKey: await kms.generateDataKey(keyAlias, 32),
5354
};
5455
}
5556

56-
export default function (data) {
57+
export default async function (data) {
5758
// Use the data key to encrypt data
5859
}
5960

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ excerpt: 'S3Client class allows interacting with AWS S3 buckets and objects'
77

88
<BlockingAwsBlockquote />
99

10-
S3Client allows interacting with AWS S3's buckets and objects. Namely, it allows the user to list buckets and the objects they contain, as well as download, uploading, and deleting objects. The S3Client operations are blocking, and we recommend reserving their usage to the [`setup`](/using-k6/test-lifecycle/) and [`teardown`](/using-k6/test-lifecycle/) functions as much as possible.
10+
`S3Client` interacts with the AWS Simple Storage Service (S3).
1111

12-
S3Client is included in both the dedicated jslib `s3.js` bundle, and the `aws.js` one, containing all the services clients.
12+
With it, you can do several operations such as list buckets, list objects in a bucket, or download objects from a bucket. For a full list of supported operations, see [Methods](#methods).
13+
14+
Both the dedicated `s3.js` jslib bundle and the all-encompassing `aws.js` bundle include the `S3Client`.
1315

1416
### Methods
1517

@@ -44,7 +46,7 @@ import { check } from 'k6';
4446
import exec from 'k6/execution';
4547
import http from 'k6/http';
4648

47-
import { AWSConfig, S3Client } from 'https://jslib.k6.io/aws/0.8.1/s3.js';
49+
import { AWSConfig, S3Client } from 'https://jslib.k6.io/aws/0.9.0/s3.js';
4850

4951
const awsConfig = new AWSConfig({
5052
region: __ENV.AWS_REGION,
@@ -57,21 +59,21 @@ const testBucketName = 'test-jslib-aws';
5759
const testInputFileKey = 'productIDs.json';
5860
const testOutputFileKey = `results-${Date.now()}.json`;
5961

60-
export function setup() {
62+
export async function setup() {
6163
// If our test bucket does not exist, abort the execution.
62-
const buckets = s3.listBuckets();
64+
const buckets = await s3.listBuckets();
6365
if (buckets.filter((b) => b.name === testBucketName).length == 0) {
6466
exec.test.abort();
6567
}
6668

6769
// If our test object does not exist, abort the execution.
68-
const objects = s3.listObjects(testBucketName);
70+
const objects = await s3.listObjects(testBucketName);
6971
if (objects.filter((o) => o.key === testInputFileKey).length == 0) {
7072
exec.test.abort();
7173
}
7274

7375
// Download the S3 object containing our test data
74-
const inputObject = s3.getObject(testBucketName, testInputFileKey);
76+
const inputObject = await s3.getObject(testBucketName, testInputFileKey);
7577

7678
// Let's return the downloaded S3 object's data from the
7779
// setup function to allow the default function to use it.
@@ -80,31 +82,33 @@ export function setup() {
8082
};
8183
}
8284

83-
export default function (data) {
85+
export default async function (data) {
8486
// Pick a random product ID from our test data
8587
const randomProductID = data.productIDs[Math.floor(Math.random() * data.productIDs.length)];
8688

8789
// Query our ecommerce website's product page using the ID
88-
const res = http.get(`http://your.website.com/product/${randomProductID}/`);
90+
const res = await http.asyncRequest("GET", `http://your.website.com/product/${randomProductID}/`);
8991
check(res, { 'is status 200': res.status === 200 });
9092
}
9193

92-
export function handleSummary(data) {
94+
export async function handleSummary(data) {
9395
// Once the load test is over, let's upload the results to our
9496
// S3 bucket. This is executed after teardown.
95-
s3.putObject(testBucketName, testOutputFileKey, JSON.stringify(data));
97+
await s3.putObject(testBucketName, testOutputFileKey, JSON.stringify(data));
9698
}
9799
```
98100

99101
</CodeGroup>
100102

103+
#### Multipart uploads
104+
101105
<CodeGroup labels={[]}>
102106

103107
```javascript
104108
import crypto from 'k6/crypto';
105109
import exec from 'k6/execution';
106110

107-
import { AWSConfig, S3Client } from 'https://jslib.k6.io/aws/0.8.1/s3.js';
111+
import { AWSConfig, S3Client } from 'https://jslib.k6.io/aws/0.9.0/s3.js';
108112

109113
const awsConfig = new AWSConfig({
110114
region: __ENV.AWS_REGION,
@@ -118,10 +122,10 @@ const s3 = new S3Client(awsConfig);
118122
const testBucketName = 'test-jslib-aws';
119123
const testFileKey = 'multipart.txt';
120124

121-
export default function () {
125+
export default async function () {
122126
// List the buckets the AWS authentication configuration
123127
// gives us access to.
124-
const buckets = s3.listBuckets();
128+
const buckets = await s3.listBuckets();
125129

126130
// If our test bucket does not exist, abort the execution.
127131
if (buckets.filter((b) => b.name === testBucketName).length == 0) {
@@ -134,11 +138,11 @@ export default function () {
134138
const bigFile = crypto.randomBytes(12 * 1024 * 1024);
135139

136140
// Initialize a multipart upload
137-
const multipartUpload = s3.createMultipartUpload(testBucketName, testFileKey);
141+
const multipartUpload = await s3.createMultipartUpload(testBucketName, testFileKey);
138142

139143
// Upload the first part
140144
const firstPartData = bigFile.slice(0, 6 * 1024 * 1024);
141-
const firstPart = s3.uploadPart(
145+
const firstPart = await s3.uploadPart(
142146
testBucketName,
143147
testFileKey,
144148
multipartUpload.uploadId,
@@ -148,7 +152,7 @@ export default function () {
148152

149153
// Upload the second part
150154
const secondPartData = bigFile.slice(6 * 1024 * 1024, 12 * 1024 * 1024);
151-
const secondPart = s3.uploadPart(
155+
const secondPart = await s3.uploadPart(
152156
testBucketName,
153157
testFileKey,
154158
multipartUpload.uploadId,
@@ -157,14 +161,14 @@ export default function () {
157161
);
158162

159163
// Complete the multipart upload
160-
s3.completeMultipartUpload(testBucketName, testFileKey, multipartUpload.uploadId, [
164+
await s3.completeMultipartUpload(testBucketName, testFileKey, multipartUpload.uploadId, [
161165
firstPart,
162166
secondPart,
163167
]);
164168

165169
// Let's redownload it verify it's correct, and delete it
166-
const obj = s3.getObject(testBucketName, testFileKey);
167-
s3.deleteObject(testBucketName, testFileKey);
170+
const obj = await s3.getObject(testBucketName, testFileKey);
171+
await s3.deleteObject(testBucketName, testFileKey);
168172
}
169173
```
170174

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ description: 'SQSClient enables interaction with the AWS Simple Queue Service (S
55
excerpt: 'SQSClient allows interacting with the AWS Simple Queue Service (SQS)'
66
---
77

8-
<BlockingAwsBlockquote />
8+
`SQSClient` interacts with the AWS Simple Queue Service (SQS).
99

10-
`SQSClient` interacts with the AWS Simple Queue Service (SQS). With it, the user can send messages to specified queues and list available queues in the current region. `SQSClient` operations are blocking.
10+
With it, the user can send messages to specified queues and list available queues in the current region.
1111

12-
Both the dedicated `sqs.js` jslib bundle and the all-encompassing `aws.js` bundle include the `SQSClient`.
12+
`SQSClient` is included in both the dedicated `sqs.js` jslib bundle and the all-encompassing `aws.js` one, containing all the services clients.
1313

1414
### Methods
1515

@@ -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.8.1/sqs.js'
37+
import { AWSConfig, SQSClient } from 'https://jslib.k6.io/aws/0.9.0/sqs.js'
3838

3939
const awsConfig = new AWSConfig({
4040
region: __ENV.AWS_REGION,
@@ -46,15 +46,15 @@ const awsConfig = new AWSConfig({
4646
const sqs = new SQSClient(awsConfig)
4747
const testQueue = 'https://sqs.us-east-1.amazonaws.com/000000000/test-queue'
4848

49-
export default function () {
49+
export default async function () {
5050
// If our test queue does not exist, abort the execution.
51-
const queuesResponse = sqs.listQueues()
51+
const queuesResponse = await sqs.listQueues()
5252
if (queuesResponse.queueUrls.filter((q) => q === testQueue).length == 0) {
5353
exec.test.abort()
5454
}
5555

5656
// Send message to test queue
57-
sqs.sendMessage(testQueue, JSON.stringify({value: '123'}));
57+
await sqs.sendMessage(testQueue, JSON.stringify({value: '123'}));
5858
}
5959
```
6060

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ description: 'SecretsManagerClient allows interacting with AWS secrets stored in
55
excerpt: 'SecretsManagerClient allows interacting with AWS secrets stored in Secrets Manager'
66
---
77

8-
<BlockingAwsBlockquote />
8+
`SecretsManagerClient` interacts with the AWS Secrets Manager.
99

10-
SecretsManagerClient allows interacting with secrets stored in AWS's Secrets Manager. Namely, it allows the user to list, download, create, modify and delete secrets. Note that the SecretsManagerClient operations are blocking, and we recommend reserving their usage to the [`setup`](/using-k6/test-lifecycle/) and [`teardown`](/using-k6/test-lifecycle/) functions as much as possible.
10+
With it, you can perform several operations such as listing, creating and downloading secrets owned by the authenticated user. For a full list of supported operations, see [Methods](#methods).
1111

12-
SecretsManagerClient is included in both the dedicated jslib `secrets-manager.js` bundle, and the `aws.js` one, containing all the services clients.
12+
`SecretsManagerClient` is included in both the dedicated jslib `secrets-manager.js` bundle, and the `aws.js` one, containing all the services clients.
1313

1414
### Methods
1515

@@ -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.8.1/secrets-manager.js';
40+
import { AWSConfig, SecretsManagerClient } from 'https://jslib.k6.io/aws/0.9.0/secrets-manager.js';
4141

4242
const awsConfig = new AWSConfig({
4343
region: __ENV.AWS_REGION,
@@ -49,39 +49,39 @@ const secretsManager = new SecretsManagerClient(awsConfig);
4949
const testSecretName = 'jslib-test-secret';
5050
const testSecretValue = 'jslib-test-value';
5151

52-
export function setup() {
52+
export async function setup() {
5353
// Let's make sure our test secret is created
54-
const testSecret = secretsManager.createSecret(
54+
const testSecret = await secretsManager.createSecret(
5555
testSecretName,
5656
testSecretValue,
5757
'this is a test secret, delete me.'
5858
);
5959

6060
// List the secrets the AWS authentication configuration
6161
// gives us access to, and verify the creation was successful.
62-
const secrets = secretsManager.listSecrets();
62+
const secrets = await secretsManager.listSecrets();
6363
if (!secrets.filter((s) => s.name === testSecret.name).length == 0) {
6464
exec.test.abort('test secret not found');
6565
}
6666
}
6767

68-
export default function () {
68+
export default async function () {
6969
// Knnowing that we know the secret exist, let's update its value
7070
const newTestSecretValue = 'new-test-value';
71-
secretsManager.putSecretValue(testSecretName, newTestSecretValue);
71+
await secretsManager.putSecretValue(testSecretName, newTestSecretValue);
7272

7373
// Let's get its value and verify it was indeed updated
74-
const updatedSecret = secretsManager.getSecret(testSecretName);
74+
const updatedSecret = await secretsManager.getSecret(testSecretName);
7575
if (updatedSecret.secret !== newTestSecretValue) {
7676
exec.test.abort('unable to update test secret');
7777
}
7878

7979
// Let's now use our secret in the context of our load test...
8080
}
8181

82-
export function teardown() {
82+
export async function teardown() {
8383
// Finally, let's clean after ourselves and delete our test secret
84-
secretsManager.deleteSecret(testSecretName, { noRecovery: true });
84+
await secretsManager.deleteSecret(testSecretName, { noRecovery: true });
8585
}
8686
```
8787

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ description: 'SignatureV4 is used to sign or pre-sign requests to AWS services u
55
excerpt: 'SignatureV4 is used to sign and pre-sign requests to AWS services using the Signature V4 algorithm'
66
---
77

8+
<BlockingAwsBlockquote />
9+
810
With SignatureV4, you can produce authenticated HTTP requests to AWS services. Namely, it lets you sign and pre-sign requests to AWS services using the [Signature V4](https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html) algorithm. The `sign` operation produces a signed request with authorization information stored in its headers.
911
The `presign` operation produces a pre-signed request with authorization information stored in its query string parameters.
1012

@@ -42,9 +44,9 @@ SignatureV4 methods throw errors on failure.
4244
<CodeGroup labels={[]}>
4345

4446
```javascript
45-
import http from 'k6/http.js'
47+
import http from 'k6/http'
4648

47-
import { AWSConfig, SignatureV4 } from 'https://jslib.k6.io/aws/0.8.1/aws.js'
49+
import { AWSConfig, SignatureV4 } from 'https://jslib.k6.io/aws/0.9.0/aws.js'
4850

4951
const awsConfig = new AWSConfig({
5052
region: __ENV.AWS_REGION,

0 commit comments

Comments
 (0)