|
| 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