aws-cdk-lib#Arn TypeScript Examples

The following examples show how to use aws-cdk-lib#Arn. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: aws.ts    From eventcatalog with MIT License 6 votes vote down vote up
getEventBusRulesAndTargets = (eventbridge: EventBridge, eventBusName: string) => async () => {
  const rulesForEvents = await eventbridge.listRules({ EventBusName: eventBusName, Limit: 100 });
  const rulesByEvent = rulesForEvents.Rules ? flattenRules(rulesForEvents.Rules) : {};

  return Object.keys(rulesByEvent).reduce(async (data, event) => {
    const listOfRulesForEvent = rulesByEvent[event].rules || [];

    const eventTargetsAndRules = listOfRulesForEvent.map(async (rule: any) => {
      const { Targets = [] } = await eventbridge.listTargetsByRule({ Rule: rule.name, EventBusName: eventBusName });
      const targets = Targets.map(({ Arn: arnString = '' }) => {
        const { service, resource, resourceName } = Arn.split(arnString, ArnFormat.SLASH_RESOURCE_SLASH_RESOURCE_NAME);
        return { service, resource, resourceName, arn: arnString };
      });
      return { ...rule, targets };
    });

    const eventWithTargetsAndRules = await Promise.all(eventTargetsAndRules);

    return {
      ...(await data),
      [event]: eventWithTargetsAndRules,
    };
  }, {});
}