Trigger

class aws_cdk.triggers.Trigger(scope, id, *, handler, invocation_type=None, timeout=None, execute_after=None, execute_before=None, execute_on_handler_change=None)

Bases: Construct

Triggers an AWS Lambda function during deployment.

ExampleMetadata:

infused

Example:

import aws_cdk.triggers as triggers


func = lambda_.Function(self, "MyFunction",
    handler="index.handler",
    runtime=lambda_.Runtime.NODEJS_18_X,
    code=lambda_.Code.from_inline("foo")
)

triggers.Trigger(self, "MyTrigger",
    handler=func,
    timeout=Duration.minutes(10),
    invocation_type=triggers.InvocationType.EVENT
)
Parameters:
  • scope (Construct) –

  • id (str) –

  • handler (Function) – The AWS Lambda function of the handler to execute.

  • invocation_type (Optional[InvocationType]) – The invocation type to invoke the Lambda function with. Default: RequestResponse

  • timeout (Optional[Duration]) – The timeout of the invocation call of the Lambda function to be triggered. Default: Duration.minutes(2)

  • execute_after (Optional[Sequence[Construct]]) – Adds trigger dependencies. Execute this trigger only after these construct scopes have been provisioned. You can also use trigger.executeAfter() to add additional dependencies. Default: []

  • execute_before (Optional[Sequence[Construct]]) – Adds this trigger as a dependency on other constructs. This means that this trigger will get executed before the given construct(s). You can also use trigger.executeBefore() to add additional dependants. Default: []

  • execute_on_handler_change (Optional[bool]) – Re-executes the trigger every time the handler changes. This implies that the trigger is associated with the currentVersion of the handler, which gets recreated every time the handler or its configuration is updated. Default: true

Methods

execute_after(*scopes)

Adds trigger dependencies.

Execute this trigger only after these construct scopes have been provisioned.

Parameters:

scopes (Construct) –

Return type:

None

execute_before(*scopes)

Adds this trigger as a dependency on other constructs.

This means that this trigger will get executed before the given construct(s).

Parameters:

scopes (Construct) –

Return type:

None

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

node

The tree node.

Static Methods

classmethod is_construct(x)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters:

x (Any) – Any object.

Return type:

bool

Returns:

true if x is an object created from a class which extends Construct.