Skip to content
v2.273.0

Trigger ​

Triggers an AWS Lambda function during deployment.

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,
});
python
import aws_cdk.triggers as triggers


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

triggers.Trigger(self, "MyTrigger",
    handler=func,
    timeout=Duration.minutes(10),
    invocation_type=triggers.InvocationType.EVENT
)
java
import software.amazon.awscdk.triggers.*;


Function func = Function.Builder.create(this, "MyFunction")
        .handler("index.handler")
        .runtime(Runtime.NODEJS_LATEST)
        .code(Code.fromInline("foo"))
        .build();

Trigger.Builder.create(this, "MyTrigger")
        .handler(func)
        .timeout(Duration.minutes(10))
        .invocationType(InvocationType.EVENT)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.Triggers;


var func = new Function(this, "MyFunction", new FunctionProps {
    Handler = "index.handler",
    Runtime = Runtime.NODEJS_LATEST,
    Code = Code.FromInline("foo")
});

new Trigger(this, "MyTrigger", new TriggerProps {
    Handler = func,
    Timeout = Duration.Minutes(10),
    InvocationType = InvocationType.EVENT
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"


func := lambda.NewFunction(this, jsii.String("MyFunction"), &FunctionProps{
	Handler: jsii.String("index.handler"),
	Runtime: lambda.Runtime_NODEJS_LATEST(),
	Code: lambda.Code_FromInline(jsii.String("foo")),
})

triggers.NewTrigger(this, jsii.String("MyTrigger"), &TriggerProps{
	Handler: func,
	Timeout: awscdk.Duration_Minutes(jsii.Number(10)),
	InvocationType: triggers.InvocationType_EVENT,
})

Initializer ​

ts
new Trigger(scope: Construct, id: string, props: TriggerProps)
python
Trigger(scope: Construct, id: str, props: TriggerProps)
java
new Trigger(Construct scope, String id, TriggerProps props)
csharp
new Trigger(Construct scope, string id, TriggerProps props)
go
NewTrigger(Scope Construct, Id *string, Props TriggerProps)

Construct Props ​

executeAfterConstruct[]execute_aftertyping.List[Construct]executeAfterList<Construct>ExecuteAfterConstruct[]ExecuteAfter*[]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.

executeBeforeConstruct[]execute_beforetyping.List[Construct]executeBeforeList<Construct>ExecuteBeforeConstruct[]ExecuteBefore*[]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 dependents.

executeOnHandlerChangebooleanexecute_on_handler_changeboolexecuteOnHandlerChangeBooleanExecuteOnHandlerChangeboolExecuteOnHandlerChange*bool= 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.

handlerFunctionhandlerFunctionhandlerFunctionHandlerFunctionHandlerFunctionrequired#
The AWS Lambda function of the handler to execute.
invocationTypeInvocationTypeinvocation_typeInvocationTypeinvocationTypeInvocationTypeInvocationTypeInvocationTypeInvocationTypeInvocationType= RequestResponse#
The invocation type to invoke the Lambda function with.
timeoutDurationtimeoutDurationtimeoutDurationTimeoutDurationTimeoutDuration= Duration.minutes(2)#
The timeout of the invocation call of the Lambda function to be triggered.

Properties ​

nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.

Methods ​

executeAfter(...scopes: Construct[]): voiddef execute_after(self, scopes: Construct) -> Nonepublic void executeAfter(Construct scopes)public void ExecuteAfter(Construct scopes)func ExecuteAfter(Scopes Construct)#
Adds trigger dependencies.

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

executeBefore(...scopes: Construct[]): voiddef execute_before(self, scopes: Construct) -> Nonepublic void executeBefore(Construct scopes)public void ExecuteBefore(Construct scopes)func ExecuteBefore(Scopes Construct)#
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@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

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

  • xxxxX — Any object.

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

toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func 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.

1 parameter · returns

Parameters

  • mixinsmixinsmixinsmixinsMixins — The mixins to apply.

Returns: This construct for chaining