or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

analytics-targets.mdapi-targets.mdcicd-targets.mdcompute-targets.mdindex.mdmessaging-targets.mdorchestration-targets.mdsystem-targets.md
tile.json

tessl/npm-aws-cdk--aws-events-targets

Event targets for Amazon EventBridge that enable routing events to various AWS services

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@aws-cdk/aws-events-targets@1.204.x

To install, run

npx @tessl/cli install tessl/npm-aws-cdk--aws-events-targets@1.204.0

index.mddocs/

AWS CDK Events Targets

⚠️ DEPRECATED: AWS CDK v1 has reached End-of-Support on 2023-06-01. This package is no longer being updated. Users should migrate to AWS CDK v2. For migration guidance, see the CDK v2 Migration Guide.

AWS CDK Events Targets provides integration classes to send Amazon EventBridge events to various AWS services. Each target class implements the EventBridge target pattern, allowing developers to easily configure event routing with support for dead letter queues, retry policies, custom input transformation, and IAM role specification.

Package Information

  • Package Name: @aws-cdk/aws-events-targets
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @aws-cdk/aws-events-targets
  • License: Apache-2.0
  • CDK Version: v1 (End-of-Support as of 2023-06-01)

Core Imports

import * as targets from "@aws-cdk/aws-events-targets";

For specific targets:

import { 
  LambdaFunction, 
  SqsQueue, 
  SnsTopic, 
  EcsTask 
} from "@aws-cdk/aws-events-targets";

Basic Usage

import * as events from "@aws-cdk/aws-events";
import * as lambda from "@aws-cdk/aws-lambda";
import * as targets from "@aws-cdk/aws-events-targets";

// Create a Lambda function
const fn = new lambda.Function(this, "MyFunc", {
  runtime: lambda.Runtime.NODEJS_14_X,
  handler: "index.handler",
  code: lambda.Code.fromInline("exports.handler = () => {}"),
});

// Create an EventBridge rule
const rule = new events.Rule(this, "MyRule", {
  eventPattern: {
    source: ["aws.ec2"],
  },
});

// Add Lambda function as target
rule.addTarget(new targets.LambdaFunction(fn, {
  retryAttempts: 2,
  maxEventAge: Duration.hours(2),
}));

Architecture

AWS CDK Events Targets is built around several key concepts:

  • Target Classes: Each AWS service has a corresponding target class implementing events.IRuleTarget
  • Configuration Props: Each target accepts service-specific configuration through props interfaces
  • Base Props: Common configuration options like dead letter queues and retry policies via TargetBaseProps
  • IAM Integration: Automatic IAM permission setup for EventBridge to invoke target services
  • Error Handling: Built-in support for dead letter queues and retry policies

Capabilities

Compute Targets

Targets for compute services including Lambda functions, ECS tasks, and Batch jobs.

class LambdaFunction implements events.IRuleTarget {
  constructor(handler: lambda.IFunction, props?: LambdaFunctionProps);
  bind(rule: events.IRule, id?: string): events.RuleTargetConfig;
}

interface LambdaFunctionProps extends TargetBaseProps {
  /** The event to send to the Lambda function as payload (default: entire EventBridge event) */
  readonly event?: events.RuleTargetInput;
}

class EcsTask implements events.IRuleTarget {
  constructor(props: EcsTaskProps);
  bind(rule: events.IRule, id?: string): events.RuleTargetConfig;
}

class BatchJob implements events.IRuleTarget {
  constructor(
    jobQueueArn: string,
    jobQueueScope: IConstruct,
    jobDefinitionArn: string,
    jobDefinitionScope: IConstruct,
    props?: BatchJobProps
  );
  bind(rule: events.IRule, id?: string): events.RuleTargetConfig;
}

interface BatchJobProps extends TargetBaseProps {
  /** The event to send to the batch job (default: entire EventBridge event) */
  readonly event?: events.RuleTargetInput;
  /** The size of the array, if this is an array batch job (valid values: 2-10,000) */
  readonly size?: number;
  /** The number of times to attempt to retry, if the job fails (valid values: 1-10) */
  readonly attempts?: number;
  /** The name of the submitted job (default: automatically generated) */
  readonly jobName?: string;
}

Compute Targets

Messaging Targets

Targets for messaging services including SQS queues and SNS topics.

class SqsQueue implements events.IRuleTarget {
  constructor(queue: sqs.IQueue, props?: SqsQueueProps);
  readonly queue: sqs.IQueue;
  bind(rule: events.IRule, id?: string): events.RuleTargetConfig;
}

interface SqsQueueProps extends TargetBaseProps {
  /** Message Group ID for messages sent to FIFO queues */
  readonly messageGroupId?: string;
  /** The message to send to the queue (default: entire EventBridge event) */
  readonly message?: events.RuleTargetInput;
}

class SnsTopic implements events.IRuleTarget {
  constructor(topic: sns.ITopic, props?: SnsTopicProps);
  readonly topic: sns.ITopic;
  bind(rule: events.IRule, id?: string): events.RuleTargetConfig;
}

interface SnsTopicProps {
  /** The message to send to the topic (default: entire EventBridge event) */
  readonly message?: events.RuleTargetInput;
}

Messaging Targets

API and HTTP Targets

Targets for API Gateway REST APIs and external HTTP endpoints via API destinations.

class ApiGateway implements events.IRuleTarget {
  constructor(restApi: api.RestApi, props?: ApiGatewayProps);
  readonly restApi: api.RestApi;
  bind(rule: events.IRule, id?: string): events.RuleTargetConfig;
}

interface ApiGatewayProps extends TargetBaseProps {
  /** The method for API resource invoked by the rule (default: '*' treated as ANY) */
  readonly method?: string;
  /** The API resource invoked by the rule (default: '/') */
  readonly path?: string;
  /** The deploy stage of API gateway invoked by the rule */
  readonly stage?: string;
  /** The headers to be set when requesting API */
  readonly headerParameters?: { [key: string]: string };
  /** The path parameter values to populate wildcards in API path */
  readonly pathParameterValues?: string[];
  /** The query parameters to be set when requesting API */
  readonly queryStringParameters?: { [key: string]: string };
  /** The post request body sent to the API (default: entire EventBridge event) */
  readonly postBody?: events.RuleTargetInput;
  /** The role to assume before invoking the target (default: new role created) */
  readonly eventRole?: iam.IRole;
}

class ApiDestination implements events.IRuleTarget {
  constructor(apiDestination: events.IApiDestination, props?: ApiDestinationProps);
  bind(rule: events.IRule, id?: string): events.RuleTargetConfig;
}

interface ApiDestinationProps extends TargetBaseProps {
  /** The event to send (default: entire EventBridge event) */
  readonly event?: events.RuleTargetInput;
  /** The role to assume before invoking the target (default: new role created) */
  readonly eventRole?: iam.IRole;
  /** Additional headers sent to the API Destination */
  readonly headerParameters?: Record<string, string>;
  /** Path parameters to insert in place of path wildcards */
  readonly pathParameterValues?: string[];
  /** Additional query string parameters sent to the API Destination */
  readonly queryStringParameters?: Record<string, string>;
}

API and HTTP Targets

CI/CD Targets

Targets for continuous integration and deployment services including CodeBuild and CodePipeline.

class CodeBuildProject implements events.IRuleTarget {
  constructor(project: codebuild.IProject, props?: CodeBuildProjectProps);
  bind(rule: events.IRule, id?: string): events.RuleTargetConfig;
}

interface CodeBuildProjectProps extends TargetBaseProps {
  /** The role to assume before invoking the target (default: new role created) */
  readonly eventRole?: iam.IRole;
  /** The event to send to CodeBuild as StartBuild API payload (default: entire EventBridge event) */
  readonly event?: events.RuleTargetInput;
}

class CodePipeline implements events.IRuleTarget {
  constructor(pipeline: codepipeline.IPipeline, options?: CodePipelineTargetOptions);
  bind(rule: events.IRule, id?: string): events.RuleTargetConfig;
}

interface CodePipelineTargetOptions extends TargetBaseProps {
  /** The role to assume before invoking the pipeline (default: new role created) */
  readonly eventRole?: iam.IRole;
}

CI/CD Targets

Analytics and Logging Targets

Targets for data streaming, analytics, and logging services including Kinesis, CloudWatch Logs, and Kinesis Data Firehose.

class KinesisStream implements events.IRuleTarget {
  constructor(stream: kinesis.IStream, props?: KinesisStreamProps);
  bind(rule: events.IRule, id?: string): events.RuleTargetConfig;
}

class CloudWatchLogGroup implements events.IRuleTarget {
  constructor(logGroup: logs.ILogGroup, props?: LogGroupProps);
  bind(rule: events.IRule, id?: string): events.RuleTargetConfig;
}

class KinesisFirehoseStream implements events.IRuleTarget {
  constructor(stream: firehose.CfnDeliveryStream, props?: KinesisFirehoseStreamProps);
  bind(rule: events.IRule, id?: string): events.RuleTargetConfig;
}

Analytics and Logging Targets

Orchestration Targets

Targets for workflow orchestration including Step Functions state machines.

class SfnStateMachine implements events.IRuleTarget {
  constructor(machine: sfn.IStateMachine, props?: SfnStateMachineProps);
  readonly machine: sfn.IStateMachine;
  bind(rule: events.IRule, id?: string): events.RuleTargetConfig;
}

Orchestration Targets

System Targets

Targets for AWS system services including EventBridge buses and AWS API calls.

class EventBus implements events.IRuleTarget {
  constructor(eventBus: events.IEventBus, props?: EventBusProps);
  bind(rule: events.IRule, id?: string): events.RuleTargetConfig;
}

class AwsApi implements events.IRuleTarget {
  constructor(props: AwsApiProps);
  bind(rule: events.IRule, id?: string): events.RuleTargetConfig;
}

System Targets

Base Configuration

Target Base Properties

Common configuration options available for most targets.

interface TargetBaseProps {
  /** SQS queue for failed event deliveries */
  readonly deadLetterQueue?: sqs.IQueue;
  /** Maximum age of requests sent to target */
  readonly maxEventAge?: Duration;
  /** Maximum number of retry attempts */
  readonly retryAttempts?: number;
}

Container Configuration

Configuration for ECS task container overrides.

interface ContainerOverride {
  /** Name of the container inside task definition */
  readonly containerName: string;
  /** Command to run inside container */
  readonly command?: string[];
  /** Environment variables to set */
  readonly environment?: TaskEnvironmentVariable[];
  /** CPU units reserved for container */
  readonly cpu?: number;
  /** Hard memory limit on container */
  readonly memoryLimit?: number;
  /** Soft memory limit on container */
  readonly memoryReservation?: number;
}

interface TaskEnvironmentVariable {
  /** Name for the environment variable (exactly one of name and namePath must be specified) */
  readonly name: string;
  /** Value of the environment variable (exactly one of value and valuePath must be specified) */
  readonly value: string;
}

Utilities

Permission Management

Utility functions for managing IAM permissions and resource policies.

function addLambdaPermission(rule: events.IRule, handler: lambda.IFunction): void;
function addToDeadLetterQueueResourcePolicy(rule: events.IRule, queue: sqs.IQueue): void;
function singletonEventRole(scope: IConstruct): iam.IRole;
function bindBaseTargetConfig(props: TargetBaseProps): object;