Skip to content

(events): configureAsyncInvoke not called #19608

Closed

Description

@thomasstep

What is the problem?

Whenever a Lambda is added as a target to an event.Rule the function.configureAsyncInvoke() function needs to be called.

If select props (retryAttempts, maxEventAge, etc.) are included during Function creation, then an AWS::Lambda::EventInvokeConfig resource is created. If those same props are added during a rule.addTarget() call through events-targets.LambdaFunctionProps, then the function.configureAsyncInvoke() function is never called resulting in the AWS::Lambda::EventInvokeConfig resource not being created.

Reproduction Steps

import { Stack, Duration } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as events from 'aws-cdk-lib/aws-events';
import * as targets from 'aws-cdk-lib/aws-events-targets';
import * as lambda from 'aws-cdk-lib/aws-lambda';

const defaultCode = `exports.handler = async function (event, context, callback) {
  try {
    const data = {
      statusCode: 201,
    };
    return data;
  } catch (uncaughtError) {
    console.error(uncaughtError);
    throw uncaughtError;
  }
}`;

export class DemoStack extends Stack {

  constructor(scope: Construct, id: string) {
    super(scope, id);

    const maxEventAgeInMinutes = 3;
    const retryAttempts = 2;
    new lambda.Function(
      this,
      `${id}-function-with`,
      {
        code: lambda.Code.fromInline(defaultCode),
        handler: 'index.handler',
        runtime: lambda.Runtime.NODEJS_14_X,
        maxEventAge: Duration.minutes(maxEventAgeInMinutes),
        retryAttempts: retryAttempts,
      },
    );
    const lambdaFunctionWithoutEventInvokeConfig = new lambda.Function(
      this,
      `${id}-function-without`,
      {
        code: lambda.Code.fromInline(defaultCode),
        handler: 'index.handler',
        runtime: lambda.Runtime.NODEJS_14_X,
      },
    );
    const rule = new events.Rule(this, `${id}-rule`, {
      schedule: events.Schedule.rate(Duration.minutes(5)),
    });
    rule.addTarget(
      new targets.LambdaFunction(
        lambdaFunctionWithoutEventInvokeConfig,
        {
          maxEventAge: Duration.minutes(maxEventAgeInMinutes),
          retryAttempts: retryAttempts,
        },
      ),
    );
  }
}

What did you expect to happen?

I expect a AWS::Lambda::EventInvokeConfig resource to be created whenever rule.addTarget() is called.

What actually happened?

No AWS::Lambda::EventInvokeConfig resource is created.

CDK CLI Version

2.17.0 (build f9cd009)

Framework Version

No response

Node.js Version

v16.13.1

OS

MacOS 11.6.4

Language

Typescript

Language Version

TypeScript (Version 4.5.2)

Other information

No response

Activity

  1. added
    bugThis issue is a bug.
    needs-triageThis issue or PR still needs to be triaged.
    on Mar 29, 2022
  2. peterwoodworth commented on Mar 29, 2022

    @peterwoodworth
    Contributor

    I don't think this is a bug - this seems out of the scope of what the eventsTargets.LambdaFunction construct is built for (adding targets for your events)

    The props (with the same names) that you're passing in to this construct are for configuring your event rule resource. If you want to configure lambda infrastructure, you'll have to create an EventInvokeConfig with a reference to your function, or simply pass in the necessary props to your function on creation if possible.

  3. added
    guidanceQuestion that needs advice or information.
    response-requestedWaiting on additional info and feedback. Will move to "closing-soon" in 7 days.
    and removed
    bugThis issue is a bug.
    needs-triageThis issue or PR still needs to be triaged.
    on Mar 29, 2022
  4. thomasstep commented on Mar 31, 2022

    @thomasstep
    Author

    @peterwoodworth I appreciate the response. That flow wasn't clear to me from the documentation, but I can handle that. Thank you!

  5. removed
    response-requestedWaiting on additional info and feedback. Will move to "closing-soon" in 7 days.
    on Mar 31, 2022
  6. peterwoodworth commented on Mar 31, 2022

    @peterwoodworth
    Contributor

    Do you have any specific suggestions on how we could improve clarity here @thomasstep? I'm not sure exactly where you got tripped up

  7. added
    response-requestedWaiting on additional info and feedback. Will move to "closing-soon" in 7 days.
    on Mar 31, 2022
  8. locked and limited conversation to collaborators on Apr 1, 2022
  9. converted this issue into a discussion #19703 on Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

@aws-cdk/aws-eventsRelated to CloudWatch EventsguidanceQuestion that needs advice or information.response-requestedWaiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions