Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Kinesis #33

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ At the moment, this library provides the following:
* `KMS`: allows to list KMS keys and generate a unique symmetric data key for use outside of AWS KMS
* `SSM`: allows to retrieve a parameter from AWS Systems Manager
* `V4 signature`: allows to sign requests to amazon AWS services
* `KinesisClient`: allows all APIs for Kinesis available by AWS.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `KinesisClient`: allows all APIs for Kinesis available by AWS.
* `KinesisClient`: use it to interact with the AWS Kinesis service.



## Want to contribute?

Expand Down Expand Up @@ -256,6 +258,52 @@ export default function () {
}
```


### Kinesis

Consult the `KinesisClient` [dedicated k6 documentation page](https://k6.io/docs/javascript-api/jslib/aws/kinesisclient) for more details on its methods and how to use it.

```javascript
import exec from 'k6/execution'

import { AWSConfig, KinesisClient } from 'https://jslib.k6.io/aws/0.7.0/kinesis.js'
import encoding from 'k6/encoding';
import { describe, expect } from 'https://jslib.k6.io/k6chaijs/4.3.4.2/index.js';
import { fail } from 'k6';

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 function () {
describe('01. List Kinesis streams', () => {
try {
const res = kinesis.listStreams()
expect(res.StreamNames.length,"number of streams").to.equal(6);
} catch(err) {
fail(err)
}

})

describe('02. List kinesis stream with arguments', () => {
try {
const res = kinesis.listStreams({Limit: 1})
expect(res.StreamNames.length,"number of streams").to.equal(1);
} catch(err) {
fail(err)
}
})
}

```



## Development

### Contributing
Expand Down
2 changes: 1 addition & 1 deletion build/aws.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/aws.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/index.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions build/kinesis.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/kinesis.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/kms.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/kms.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/s3.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/s3.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/secrets-manager.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/secrets-manager.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/signature.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/signature.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/sqs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/sqs.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/ssm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/ssm.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
environment:
- SERVICES=s3,secretsmanager,sqs,kms,ssm
- SERVICES=s3,secretsmanager,sqs,kms,ssm,kinesis
- DEFAULT_REGION=us-east-1
- DEBUG=${DEBUG-}
- PERSISTENCE=${PERSISTENCE-}
Expand Down
128 changes: 128 additions & 0 deletions examples/kinesis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import exec from 'k6/execution'

import { AWSConfig, KinesisClient } from '../build/kinesis.js'
import encoding from 'k6/encoding';
import { describe, expect } from 'https://jslib.k6.io/k6chaijs/4.3.4.2/index.js';
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)

const getShardIds = () => {
const res = kinesis.listShards({
StreamName: dummyStream,
})
const shardIds = res.Shards.map(shard => shard.ShardId);

return shardIds
}

const getShardIterator = (shardId) => {
const res = kinesis.getShardIterator({
StreamName: dummyStream,
ShardId: shardId,
ShardIteratorType: `TRIM_HORIZON`
})
return res.ShardIterator
}

export default function () {
describe('01. Create kinesis Stream', () => {
try {
// Valid Values: PROVISIONED | ON_DEMAND
kinesis.createStream({

"ShardCount": 10,
"StreamModeDetails": {
"StreamMode": "PROVISIONED"
},
"StreamName": dummyStream

})
} catch (err) {
fail(err)
}
})

describe('02. List Kinesis streams', () => {
try {
const res = kinesis.listStreams()
expect(res.StreamNames.length, "number of streams").to.equal(1);
} catch (err) {
fail(err)
}
})


describe('03. List kinesis stream with arguments', () => {
try {
const res = kinesis.listStreams({ Limit: 1 })
expect(res.StreamNames.length, "number of streams").to.equal(1);
} catch (err) {
fail(err)
}
sleep(2)
})


describe('04. publish to kinesis Stream', () => {
try {
for (let i = 0; i < 50; i++) {
const res = 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"
}
]
})
expect(res.FailedRecordCount, `Failed Records to publish`).to.equal(0);
expect(res.Records.length, `Total Records`).to.equal(2);
}
} catch (err) {
fail(err)
}
})



describe('05. Gets an Amazon Kinesis read all data ', () => {
try {
const shards = getShardIds()
shards.map(shard => {
let iterator = getShardIterator(shard)
while (true) {
const res = kinesis.getRecords({ ShardIterator: iterator })
iterator = res.NextShardIterator

if (!res.MillisBehindLatest || res.MillisBehindLatest == `0`) {
break
}
}
})
} catch (err) {
fail(err)
}
})


describe('06. Delete kinesis Stream', () => {
try {
kinesis.deleteStream({ StreamName: dummyStream })
} catch (err) {
fail(err)
}
})
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
SystemsManagerParameter,
SystemsManagerServiceError,
} from './internal/ssm'
import { KinesisClient } from './internal/kinesis'

// Re-Export public symbols
export {
Expand Down Expand Up @@ -45,4 +46,6 @@ export {
SystemsManagerClient,
SystemsManagerParameter,
SystemsManagerServiceError,
// Kinesis
KinesisClient
}
Loading