# Trigger

Triggers an AWS Lambda function during deployment.

Extends: Construct › Trigger
Implements: ITrigger, IConstruct, IDependable

- Source: [`triggers/lib/trigger.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/triggers/lib/trigger.ts#L114)
- Type last changed: v2.15.0 · 1 Mar 2022

## Example

```ts
import * as triggers from 'aws-cdk-lib/triggers';

const func = new lambda.Function(this, 'MyFunction', {
  handler: 'index.handler',
  runtime: lambda.Runtime.NODEJS_LATEST,
  code: lambda.Code.fromInline('foo'),
});

new triggers.Trigger(this, 'MyTrigger', {
  handler: func,
  timeout: Duration.minutes(10),
  invocationType: triggers.InvocationType.EVENT,
});
```

## Initializer

```ts
new Trigger(scope: Construct, id: string, props: TriggerProps)
```

## Construct Props

- `executeAfter`: [Construct](/cdk/api/v2/docs/constructs.Construct.html)[] = [] — Adds trigger dependencies. Execute this trigger only after these construct scopes have been provisioned.

  You can also use `trigger.executeAfter()` to add additional dependencies.

- `executeBefore`: [Construct](/cdk/api/v2/docs/constructs.Construct.html)[] = [] — 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 dependents.

- `executeOnHandlerChange`: boolean = true — 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.

- `handler`: [Function](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Function.html) (required) — The AWS Lambda function of the handler to execute.

- `invocationType`: [InvocationType](/cdk/api/v2/docs/aws-cdk-lib.triggers.InvocationType.html) = RequestResponse — The invocation type to invoke the Lambda function with.

- `timeout`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = Duration.minutes(2) — The timeout of the invocation call of the Lambda function to be triggered.

## Properties

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) (required) — The tree node.

## Methods

- `executeAfter(...scopes: Construct[]): void` — Adds trigger dependencies.

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

- `executeBefore(...scopes: Construct[]): void` — Adds this trigger as a dependency on other constructs.

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

- `isConstruct(x: any): boolean` (static) — 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 object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
