本文介绍如何使用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 deleteEventRuleSample(client: EventBridge): Promise<void> {
        try {
            let deleteRuleRequest = new $EventBridge.DeleteRuleRequest({ });
            deleteRuleRequest.ruleName = "myRule";
            deleteRuleRequest.eventBusName = "demo-bus";
            let resp = await client.deleteRule(deleteRuleRequest);
            Console.log("--------------------delete 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.deleteEventRuleSample(client);
    }

}

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