-
Notifications
You must be signed in to change notification settings - Fork 29
/
kinesis.js
68 lines (56 loc) · 2.05 KB
/
kinesis.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { AWSConfig, KinesisClient } from '../dist/kinesis.js'
import encoding from 'k6/encoding'
import { fail } from 'k6'
const dummyStream = `kinesis-test-stream-provisioned`
const awsConfig = new AWSConfig({
region: __ENV.AWS_REGION,
accessKeyId: __ENV.AWS_ACCESS_KEY_ID,
secretAccessKey: __ENV.AWS_SECRET_ACCESS_KEY,
sessionToken: __ENV.AWS_SESSION_TOKEN,
})
const kinesis = new KinesisClient(awsConfig)
export default async function () {
// List the streamds the AWS authentication configuration
// gives us access to.
const streams = await kinesis.listStreams()
if (streams.StreamNames.filter((s) => s === dummyStream).length == 0) {
fail(`Stream ${dummyStream} does not exist`)
}
// Create our test stream
await kinesis.createStream(dummyStream, {
ShardCount: 10,
StreamModeDetails: {
StreamMode: 'PROVISIONED',
},
})
// Put some records in it
await kinesis.putRecords({
StreamName: dummyStream,
Records: [
{
Data: encoding.b64encode(JSON.stringify({ this: 'is', a: 'test' })),
PartitionKey: 'partitionKey1',
},
{
Data: encoding.b64encode(JSON.stringify([{ this: 'is', second: 'test' }])),
PartitionKey: 'partitionKey2',
},
],
})
// List the streams' shards
const shards = await kinesis.listShards(dummyStream).Shards.map((shard) => shard.ShardId)
// For each shard, read all the data
shards.map(async (shard) => {
let iterator = await kinesis.getShardIterator(dummyStream, shard.id, `TRIM_HORIZON`)
let shouldBreak = false;
while (!shouldBreak) {
const res = await kinesis.getRecords({ ShardIterator: iterator })
iterator = res.NextShardIterator
if (!res.MillisBehindLatest || res.MillisBehindLatest == `0`) {
shouldBreak = true
}
}
})
// Delete the stream
await kinesis.deleteStream({ StreamName: dummyStream })
}