本文介绍如何使用TypeScript SDK获取一个事件规则的详细信息。

示例代码如下:

import EventBridge, * as $EventBridge from '@alicloud/eventbridge';
import Util from '@alicloud/tea-util';
import Console from '@alicloud/tea-console';
import * as $tea from '@alicloud/tea-typescript';

export default class Client {

    /**
     * Create client初始化公共请求参数。
     */
    static async createClient(): Promise<EventBridge> {
        let config = new $EventBridge.Config({ });
        // 您的AccessKey ID。
        config.accessKeyId = "<accessKeyId>";
        // 您的AccessKey Secret。
        config.accessKeySecret = "<accessKeySecret>";
        // 您的接入点。
        config.endpoint = "<endpoint>";
        return new EventBridge(config);
    }

    static async getEventRuleSample(client: EventBridge): Promise<void> {
        try {
            let getEventRuleRequest = new $EventBridge.GetRuleRequest({ });
            getEventRuleRequest.ruleName = "myRule";
            getEventRuleRequest.eventBusName = "demo-bus";
            let resp = await client.getRule(getEventRuleRequest);
            Console.log("--------------------get rule success--------------------");
            Console.log(Util.toJSONString($tea.toMap(resp)));
        } catch (error) {
            Console.log(error.message);
        }
    }

    static async main(args: string[]): Promise<void> {
        let client = await Client.createClient();
        await Client.getEventRuleSample(client);
    }

}

Client.main(process.argv.slice(2));