-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document the aws jslib's EventBridge support
- Loading branch information
Showing
3 changed files
with
139 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/data/markdown/docs/20 jslib/01 jslib/01 aws/00 EventBridge.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
title: 'EventBridgeClient' | ||
head_title: 'EventBridgeClient' | ||
description: 'EventBridgeClient allows interacting with AWS EventBridge service' | ||
excerpt: 'EventBridgeClient class allows sending custom events to Amazon EventBridge so that they can be matched to rules.' | ||
--- | ||
|
||
`EventBridgeClient` interacts with the AWS EventBridge service. | ||
|
||
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). | ||
|
||
Both the dedicated `event-bridge.js` jslib bundle and the all-encompassing `aws.js` bundle include the `EventBridgeClient`. | ||
|
||
### Methods | ||
|
||
| Function | Description | | ||
| :--------------------------------------------------------------------------------------------- | :------------------------------------------------- | | ||
| [putEvents(input)](/javascript-api/jslib/aws/eventbridgeclient/eventbridgeclient-putevents/) | Send custom events to Amazon EventBridge | | ||
|
||
### Throws | ||
|
||
EventBridgeClient methods will throw errors in case of failure. | ||
|
||
| Error | Condition | | ||
| :----------------------- | :-------------------------------------------------------------------------- | | ||
| InvalidSignatureError | when invalid credentials were provided or the request signature is invalid. | | ||
| EventBridgeServiceError | when AWS replied to the requested operation with an error. | | ||
|
||
### Examples | ||
|
||
<CodeGroup labels={[]}> | ||
|
||
```javascript | ||
import { AWSConfig, EventBridgeClient } from 'https://jslib.k6.io/aws/0.10.0/event-bridge.js'; | ||
|
||
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 eventBridge = new EventBridgeClient(awsConfig); | ||
|
||
export default async function () { | ||
const eventDetails = { | ||
Source: 'my.custom.source', | ||
Detail: { key1: 'value1', key2: 'value2' }, | ||
DetailType: 'MyDetailType', | ||
Resources: ['arn:aws:resource1'], | ||
}; | ||
|
||
const input = { | ||
Entries: [eventDetails] | ||
}; | ||
|
||
try { | ||
await eventBridge.putEvents(input); | ||
} catch (error) { | ||
console.error(`Failed to put events: ${error.message}`); | ||
} | ||
} | ||
``` | ||
|
||
</CodeGroup> |
70 changes: 70 additions & 0 deletions
70
src/data/markdown/docs/20 jslib/01 jslib/01 aws/EventBridgeClient/putEvents.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
title: 'EventBridgeClient.putEvents' | ||
description: 'EventBridgeClient.putEvents sends custom events to Amazon EventBridge' | ||
excerpt: 'EventBridgeClient.putEvents sends custom events to Amazon EventBridge' | ||
--- | ||
|
||
`EventBridgeClient.putEvents` sends custom events to Amazon EventBridge so that they can be matched to rules. | ||
|
||
### Parameters | ||
|
||
| Parameter | Type | Description | | ||
| :------------ | :-------------- | :----------------------------------------------------------------------------------------------------------------------- | | ||
| input | [PutEventsInput](#puteventsinput) | An array of objects representing events to be submitted. | | ||
|
||
#### PutEventsInput | ||
|
||
| Parameter | Type | Description | | ||
| :-------- | :-------------- | :----------------------------------------------------------------------------------------------------------------------- | | ||
| Entries | [EventBridgeEntry](#eventbridgeentry)[] | An array of objects representing events to be submitted. | | ||
| EndpointId | string (optional) | The ID of the target to receive the event. | | ||
|
||
#### EventBridgeEntry | ||
|
||
| Parameter | Type | Description | | ||
| :-------- | :----- | :----------------------------------------------------------------------------------------------------------------------- | | ||
| Source | string | The source of the event. | | ||
| Detail | object | A JSON object containing event data. | | ||
| DetailType | string | Free-form string used to decide what fields to expect in the event detail. | | ||
| Resources | string[] (optional) | AWS resources, identified by Amazon Resource Name (ARN), which the event primarily concerns. | | ||
| 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. | | ||
|
||
|
||
### Returns | ||
|
||
| Type | Description | | ||
| :-------------- | :---------------------------------------------------------------------------------- | | ||
| `Promise<void>` | A Promise that fulfills when the events have been sent to Amazon EventBridge. | | ||
|
||
### Example | ||
|
||
<CodeGroup labels={[]}> | ||
|
||
```javascript | ||
import { AWSConfig, EventBridgeClient } from 'https://jslib.k6.io/aws/0.10.0/event-bridge.js'; | ||
|
||
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 eventBridge = new EventBridgeClient(awsConfig); | ||
const eventEntry = { | ||
Source: "my.source", | ||
Detail: { | ||
key: "value" | ||
}, | ||
DetailType: "MyDetailType", | ||
Resources: ["resource-arn"], | ||
}; | ||
|
||
export default async function () { | ||
await eventBridge.putEvents({ | ||
Entries: [eventEntry] | ||
}); | ||
} | ||
``` | ||
|
||
</CodeGroup> |