ApiGateway
- class aws_cdk.aws_events_targets.ApiGateway(rest_api, *, event_role=None, header_parameters=None, method=None, path=None, path_parameter_values=None, post_body=None, query_string_parameters=None, stage=None, dead_letter_queue=None, max_event_age=None, retry_attempts=None)
Bases:
object
Use an API Gateway REST APIs as a target for Amazon EventBridge rules.
- ExampleMetadata:
infused
Example:
import aws_cdk.aws_apigateway as api import aws_cdk.aws_lambda as lambda_ rule = events.Rule(self, "Rule", schedule=events.Schedule.rate(Duration.minutes(1)) ) fn = lambda_.Function(self, "MyFunc", handler="index.handler", runtime=lambda_.Runtime.NODEJS_LATEST, code=lambda_.Code.from_inline("exports.handler = e => {}") ) rest_api = api.LambdaRestApi(self, "MyRestAPI", handler=fn) dlq = sqs.Queue(self, "DeadLetterQueue") rule.add_target( targets.ApiGateway(rest_api, path="/*/test", method="GET", stage="prod", path_parameter_values=["path-value"], header_parameters={ "Header1": "header1" }, query_string_parameters={ "QueryParam1": "query-param-1" }, dead_letter_queue=dlq ))
- Parameters:
rest_api (
IRestApi
) –IRestApi implementation to use as event target.
event_role (
Optional
[IRole
]) – The role to assume before invoking the target (i.e., the pipeline) when the given rule is triggered. Default: - a new role will be createdheader_parameters (
Optional
[Mapping
[str
,str
]]) – The headers to be set when requesting API. Default: no header parametersmethod (
Optional
[str
]) – The method for api resource invoked by the rule. Default: ‘*’ that treated as ANYpath (
Optional
[str
]) – 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. Default: ‘/’path_parameter_values (
Optional
[Sequence
[str
]]) – The path parameter values to be used to populate to wildcards(“*”) of requesting api path. Default: no path parameterspost_body (
Optional
[RuleTargetInput
]) – This will be the post request body send to the API. Default: the entire EventBridge eventquery_string_parameters (
Optional
[Mapping
[str
,str
]]) – The query parameters to be set when requesting API. Default: no querystring parametersstage (
Optional
[str
]) – The deploy stage of api gateway invoked by the rule. Default: the value of deploymentStage.stageName of target api gateway.dead_letter_queue (
Optional
[IQueue
]) – 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. Default: - no dead-letter queuemax_event_age (
Optional
[Duration
]) – The maximum age of a request that Lambda sends to a function for processing. Minimum value of 60. Maximum value of 86400. Default: Duration.hours(24)retry_attempts (
Union
[int
,float
,None
]) – The maximum number of times to retry when the function returns an error. Minimum value of 0. Maximum value of 185. Default: 185
Methods
- bind(rule, _id=None)
Returns a RuleTarget that can be used to trigger this API Gateway REST APIs as a result from an EventBridge event.
- Parameters:
rule (
IRule
) –_id (
Optional
[str
]) –
- See:
- Return type:
Attributes
- i_rest_api
Returns the target IRestApi.
- rest_api
Use the
iRestApi
getter instead- Stability:
deprecated
- Type:
deprecated