aws-cdk-lib.aws_events_targets.ApiGatewayProps

interface ApiGatewayProps

LanguageType name
.NETAmazon.CDK.AWS.Events.Targets.ApiGatewayProps
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awseventstargets#ApiGatewayProps
Javasoftware.amazon.awscdk.services.events.targets.ApiGatewayProps
Pythonaws_cdk.aws_events_targets.ApiGatewayProps
TypeScript (source)aws-cdk-lib » aws_events_targets » ApiGatewayProps

Customize the API Gateway Event Target.

Example

import * as api from 'aws-cdk-lib/aws-apigateway';
import * as lambda from 'aws-cdk-lib/aws-lambda';

const rule = new events.Rule(this, 'Rule', {
  schedule: events.Schedule.rate(Duration.minutes(1)),
});

const fn = new lambda.Function( this, 'MyFunc', {
  handler: 'index.handler',
  runtime: lambda.Runtime.NODEJS_14_X,
  code: lambda.Code.fromInline( 'exports.handler = e => {}' ),
} );

const restApi = new api.LambdaRestApi( this, 'MyRestAPI', { handler: fn } );

const dlq = new sqs.Queue(this, 'DeadLetterQueue');

rule.addTarget(
  new targets.ApiGateway( restApi, {
    path: '/*/test',
    method: 'GET',
    stage:  'prod',
    pathParameterValues: ['path-value'],
    headerParameters: {
      Header1: 'header1',
    },
    queryStringParameters: {
      QueryParam1: 'query-param-1',
    },
    deadLetterQueue: dlq
  } ),
)

Properties

NameTypeDescription
deadLetterQueue?IQueueThe SQS queue to be used as deadLetterQueue. Check out the considerations for using a dead-letter queue.
eventRole?IRoleThe role to assume before invoking the target (i.e., the pipeline) when the given rule is triggered.
headerParameters?{ [string]: string }The headers to be set when requesting API.
maxEventAge?DurationThe maximum age of a request that Lambda sends to a function for processing.
method?stringThe method for api resource invoked by the rule.
path?stringThe api resource invoked by the rule.
pathParameterValues?string[]The path parameter values to be used to populate to wildcards("*") of requesting api path.
postBody?RuleTargetInputThis will be the post request body send to the API.
queryStringParameters?{ [string]: string }The query parameters to be set when requesting API.
retryAttempts?numberThe maximum number of times to retry when the function returns an error.
stage?stringThe deploy stage of api gateway invoked by the rule.

deadLetterQueue?

Type: IQueue (optional, default: no dead-letter queue)

The SQS queue to be used as deadLetterQueue. Check out the considerations for using a dead-letter queue.

The events not successfully delivered are automatically retried for a specified period of time, depending on the retry policy of the target. If an event is not delivered before all retry attempts are exhausted, it will be sent to the dead letter queue.


eventRole?

Type: IRole (optional, default: a new role will be created)

The role to assume before invoking the target (i.e., the pipeline) when the given rule is triggered.


headerParameters?

Type: { [string]: string } (optional, default: no header parameters)

The headers to be set when requesting API.


maxEventAge?

Type: Duration (optional, default: Duration.hours(24))

The maximum age of a request that Lambda sends to a function for processing.

Minimum value of 60. Maximum value of 86400.


method?

Type: string (optional, default: '' that treated as ANY)*

The method for api resource invoked by the rule.


path?

Type: string (optional, default: '/')

The api resource invoked by the rule.

We can use wildcards('*') to specify the path. In that case, an equal number of real values must be specified for pathParameterValues.


pathParameterValues?

Type: string[] (optional, default: no path parameters)

The path parameter values to be used to populate to wildcards("*") of requesting api path.


postBody?

Type: RuleTargetInput (optional, default: the entire EventBridge event)

This will be the post request body send to the API.


queryStringParameters?

Type: { [string]: string } (optional, default: no querystring parameters)

The query parameters to be set when requesting API.


retryAttempts?

Type: number (optional, default: 185)

The maximum number of times to retry when the function returns an error.

Minimum value of 0. Maximum value of 185.


stage?

Type: string (optional, default: the value of deploymentStage.stageName of target api gateway.)

The deploy stage of api gateway invoked by the rule.