Skip to content

Commit 04c2065

Browse files
authored
Merge pull request #1348 from grafana/aws/EventBridge
2 parents c8f77c3 + 7763347 commit 04c2065

File tree

3 files changed

+139
-2
lines changed

3 files changed

+139
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ description: "aws is a library implementing APIs for accessing a selection of AW
77
The `aws` module is a JavaScript library that wraps around some Amazon AWS services API.
88

99
The library exposes a couple of configuration and client classes allowing to interact with a subset of AWS services in the context of k6 load test scripts:
10+
- [EventBridge](/javascript-api/jslib/aws/eventbridgeclient): a class to send custom events to Amazon EventBridge.
11+
- [KMSClient](/javascript-api/jslib/aws/kmsclient): a class to list and generate keys from the AWS Key Management Service.
1012
- [S3Client](/javascript-api/jslib/aws/s3client): a class to list S3 buckets and the objects they contain, as well as uploading, downloading and deleting objects from them.
1113
- [SecretsManagerClient](/javascript-api/jslib/aws/secretsmanagerclient): a class to list, get, create, update, and delete secrets from the AWS secrets manager service.
12-
- [KMSClient](/javascript-api/jslib/aws/kmsclient): a class to list and generate keys from the AWS Key Management Service.
13-
- [SystemsManagerClient](/javascript-api/jslib/aws/systemsmanagerclient): a class to fetch parameters from the AWS Systems Manager Service.
1414
- [SQSClient](/javascript-api/jslib/aws/sqsclient): a class to list and send messages to SQS queues.
15+
- [SystemsManagerClient](/javascript-api/jslib/aws/systemsmanagerclient): a class to fetch parameters from the AWS Systems Manager Service.
1516
- [SignatureV4](/javascript-api/jslib/aws/signaturev4): a class to 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.
1617
- [AWSConfig](/javascript-api/jslib/aws/awsconfig/): a class is used by each client classes to provide them access to AWS credentials as well as configuration.
1718

@@ -34,6 +35,7 @@ This documentation is for the last version only. If you discover that some code
3435
| Library | Description |
3536
| :--------------------------------------------------------------------- | :------------------------------------------------------------------- |
3637
| [AWSConfig](/javascript-api/jslib/aws/awsconfig) | Class to configure AWS client classes. |
38+
| [EventBridge](/javascript-api/jslib/aws/eventbridgeclient) | Client class to interact with AWS EventBridge service. |
3739
| [KMSClient](/javascript-api/jslib/aws/kmsclient) | Client class to interact with AWS Key Management Service. |
3840
| [S3Client](/javascript-api/jslib/aws/s3client) | Client class to interact with AWS S3 buckets and objects. |
3941
| [SecretsManager](/javascript-api/jslib/aws/secretsmanagerclient) | Client class to interact with AWS secrets stored in Secrets Manager. |
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: 'EventBridgeClient'
3+
head_title: 'EventBridgeClient'
4+
description: 'EventBridgeClient allows interacting with AWS EventBridge service'
5+
excerpt: 'EventBridgeClient class allows sending custom events to Amazon EventBridge so that they can be matched to rules.'
6+
---
7+
8+
`EventBridgeClient` interacts with the AWS EventBridge service.
9+
10+
With it, you can send custom events to Amazon EventBridge. These events can then be matched to rules defined in EventBridge. For a full list of supported operations, see [Methods](#methods).
11+
12+
Both the dedicated `event-bridge.js` jslib bundle and the all-encompassing `aws.js` bundle include the `EventBridgeClient`.
13+
14+
### Methods
15+
16+
| Function | Description |
17+
| :--------------------------------------------------------------------------------------------- | :------------------------------------------------- |
18+
| [putEvents(input)](/javascript-api/jslib/aws/eventbridgeclient/eventbridgeclient-putevents/) | Send custom events to Amazon EventBridge. |
19+
20+
### Throws
21+
22+
EventBridgeClient methods will throw errors in case of failure.
23+
24+
| Error | Condition |
25+
| :----------------------- | :-------------------------------------------------------------------------- |
26+
| InvalidSignatureError | when invalid credentials were provided or the request signature is invalid. |
27+
| EventBridgeServiceError | when AWS replied to the requested operation with an error. |
28+
29+
### Examples
30+
31+
<CodeGroup labels={[]}>
32+
33+
```javascript
34+
import { AWSConfig, EventBridgeClient } from 'https://jslib.k6.io/aws/0.10.0/event-bridge.js';
35+
36+
const awsConfig = new AWSConfig({
37+
region: __ENV.AWS_REGION,
38+
accessKeyId: __ENV.AWS_ACCESS_KEY_ID,
39+
secretAccessKey: __ENV.AWS_SECRET_ACCESS_KEY,
40+
sessionToken: __ENV.AWS_SESSION_TOKEN,
41+
});
42+
43+
const eventBridge = new EventBridgeClient(awsConfig);
44+
45+
export default async function () {
46+
const eventDetails = {
47+
Source: 'my.custom.source',
48+
Detail: { key1: 'value1', key2: 'value2' },
49+
DetailType: 'MyDetailType',
50+
Resources: ['arn:aws:resource1'],
51+
};
52+
53+
const input = {
54+
Entries: [eventDetails]
55+
};
56+
57+
try {
58+
await eventBridge.putEvents(input);
59+
} catch (error) {
60+
console.error(`Failed to put events: ${error.message}`);
61+
}
62+
}
63+
```
64+
65+
</CodeGroup>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: 'EventBridgeClient.putEvents'
3+
description: 'EventBridgeClient.putEvents sends custom events to Amazon EventBridge'
4+
excerpt: 'EventBridgeClient.putEvents sends custom events to Amazon EventBridge'
5+
---
6+
7+
`EventBridgeClient.putEvents` sends custom events to Amazon EventBridge so that they can be matched to rules.
8+
9+
### Parameters
10+
11+
| Parameter | Type | Description |
12+
| :------------ | :-------------- | :----------------------------------------------------------------------------------------------------------------------- |
13+
| input | [PutEventsInput](#puteventsinput) | An array of objects representing events to be submitted. |
14+
15+
#### PutEventsInput
16+
17+
| Parameter | Type | Description |
18+
| :-------- | :-------------- | :----------------------------------------------------------------------------------------------------------------------- |
19+
| Entries | [EventBridgeEntry](#eventbridgeentry)[] | An array of objects representing events to be submitted. |
20+
| EndpointId | string (optional) | The ID of the target to receive the event. |
21+
22+
#### EventBridgeEntry
23+
24+
| Parameter | Type | Description |
25+
| :-------- | :----- | :----------------------------------------------------------------------------------------------------------------------- |
26+
| Source | string | The source of the event. |
27+
| Detail | object | A JSON object containing event data. |
28+
| DetailType | string | Free-form string used to decide what fields to expect in the event detail. |
29+
| Resources | string[] (optional) | AWS resources, identified by Amazon Resource Name (ARN), which the event primarily concerns. |
30+
| EventBusName | string (optional) | The event bus that will receive the event. If you omit this, the default event bus is used. Only the AWS account that owns a bus can write to it. |
31+
32+
33+
### Returns
34+
35+
| Type | Description |
36+
| :-------------- | :---------------------------------------------------------------------------------- |
37+
| `Promise<void>` | A Promise that fulfills when the events have been sent to Amazon EventBridge. |
38+
39+
### Example
40+
41+
<CodeGroup labels={[]}>
42+
43+
```javascript
44+
import { AWSConfig, EventBridgeClient } from 'https://jslib.k6.io/aws/0.10.0/event-bridge.js';
45+
46+
const awsConfig = new AWSConfig({
47+
region: __ENV.AWS_REGION,
48+
accessKeyId: __ENV.AWS_ACCESS_KEY_ID,
49+
secretAccessKey: __ENV.AWS_SECRET_ACCESS_KEY,
50+
sessionToken: __ENV.AWS_SESSION_TOKEN,
51+
});
52+
53+
const eventBridge = new EventBridgeClient(awsConfig);
54+
const eventEntry = {
55+
Source: "my.source",
56+
Detail: {
57+
key: "value"
58+
},
59+
DetailType: "MyDetailType",
60+
Resources: ["resource-arn"],
61+
};
62+
63+
export default async function () {
64+
await eventBridge.putEvents({
65+
Entries: [eventEntry]
66+
});
67+
}
68+
```
69+
70+
</CodeGroup>

0 commit comments

Comments
 (0)