菜单
开源 RSS

EventBridgeClient

EventBridgeClient 与 AWS EventBridge 服务交互。

通过它,您可以向 Amazon EventBridge 发送自定义事件。然后,这些事件可以与 EventBridge 中定义的规则进行匹配。有关支持的操作的完整列表,请参见 方法

专用的 event-bridge.js jslib bundle 和全面的 aws.js bundle 都包含 EventBridgeClient

方法

函数描述
putEvents(input)将自定义事件发送到 Amazon EventBridge。

抛出

EventBridgeClient 方法在失败时会抛出错误。

Error条件
InvalidSignatureError提供无效凭证或请求签名无效时。
EventBridgeServiceErrorAWS 在对请求的操作回复错误时。

示例

JavaScript
import {
  AWSConfig,
  EventBridgeClient,
} from 'https://jslib.k6.io/aws/0.13.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}`);
  }
}