v0.9.0
What's changed
The following public methods have become asynchronous in this release:
KinesisClient
KMSClient
S3Client
SecretsManagerClient
SQSClient
SystemsManagerClient
However, the SignatureV4
class and its methods remain synchronous.
What this Means for You
Asynchronous Methods
In version v0.9.0
, client methods are now async
functions, which means they return a Promise
instead of a data type. For instance, the S3Client.listBuckets
method, previously defined as listBuckets(): Array<S3Bucket>
, is now an async function: async listBuckets(): Promise<Array<S3Bucket>>
.
Using the Asynchronous Methods
You can handle the returned Promise
using the await
keyword. This way, your asynchronous code will have a synchronous look and feel. Here's an example:
export default async function () {
// ...
const buckets = await s3.listBuckets()
}
Note: k6's setup, teardown, handleSummary, and default functions can be declared as async functions.
## Full Example
```javascript
import exec from 'k6/execution'
import { AWSConfig, S3Client } from 'https://jslib.k6.io/aws/0.9.0/s3.js'
const testFile = open('bonjour.txt', 'r')
const awsConfig = new AWSConfig.fromEnvironment()
const s3 = new S3Client(awsConfig)
const testBucketName = 'test-jslib-aws'
const testFileKey = 'bonjour.txt'
export default async function () {
const buckets = await s3.listBuckets()
if (buckets.filter((b) => b.name === testBucketName).length == 0) {
exec.test.abort()
}
await s3.putObject(testBucketName, testFileKey, testFile)
const objects = await s3.listObjects(testBucketName)
if (objects.filter((o) => o.key === testFileKey).length == 0) {
exec.test.abort()
}
const obj = await s3.getObject(testBucketName, testFileKey)
await s3.deleteObject(testBucketName, testFileKey)
}
Compatibility with Older k6 Versions
If you're using an older version of k6 that doesn't support asynchronous code execution, we recommend staying with v0.8.1 until you upgrade your k6 version.