Skip to content

Triggers: executed on update even executeOnHandlerChange: false #25939

@ctapobep

Description

@ctapobep

Describe the bug

Even if I set executeOnHandlerChange: false, the function gets executed on every deployment. This happens regardless of whether I just changed executeOnHandlerChange to false or if I first deployed with this flag, and then changed my function.

It doesn't seems like this property is used anywhere within CDK.

Expected Behavior

The handler is invoked just once - when Stack is originally created. Alternatively, just remove the option so that it doesn't confuse.

Current Behavior

The handler is executed every time I run cdk deploy

Reproduction Steps

Here's the CDK script:

const app = new App();
const mainStack = new Stack(app, 'Stas-HelloWorld', {env});
let scriptDir = 'Lambda-HelloWorld';
new Trigger(mainStack, 'InitDbTriggerForLambda', {
    handler: new Function(mainStack, scriptDir, {
        runtime: Runtime.NODEJS_16_X,
        code: Code.fromAsset(scriptDir),
        handler: 'lambda.handler',
        timeout: Duration.seconds(120),
        logRetention: RetentionDays.ONE_DAY
    }),
    executeAfter: [mainStack],
    executeOnHandlerChange: false
});

Originally the function did nothing, just declared the handler. Then I changed it so that it throws an error to be sure that it's actually invoked (this made the deployment fail):

 exports.handler = async function(event) {
    throw new Error("ooops");
 }

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.82.0

Framework Version

No response

Node.js Version

v18.16.0

OS

MacOS

Language

Typescript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/triggersRelated to the triggers packagebugThis issue is a bug.effort/mediumMedium work item – several days of effortp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions