Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(lambda): Remove requirement to call currentVersion in order for currentVersionOptions to take effect #27136

Open
SamStephens opened this issue Sep 14, 2023 · 0 comments
Labels
@aws-cdk/aws-lambda Related to AWS Lambda effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@SamStephens
Copy link
Contributor

Describe the bug

Specifying currentVersionOptions for a Function has no effect unless currentVersion is invoked.

It's easy to see why this is with cdk diff, because these options actually apply to a brand new AWS::Lambda::Version resource that doesn't exist unless currentVersion is invoked. But it's a confusing behavior, and there doesn't seem to be any scenario where a user would specify currentVersionOptions for a Function and not want a AWS::Lambda::Version resource to be created with those options.

Expected Behavior

Specifying currentVersionOptions to provide options for the current version of the Lambda Function without any subsequent interaction being required.

Current Behavior

Specifying currentVersionOptions for a Function has no effect unless the currentVersion method is called.

Reproduction Steps

(Copied from #23002).

export class LambdaAutoScalingStack extends cdk.Stack {
    constructor(scope: cdk.App, id: string) {
        super(scope, id);

        new lambda.Function(this, 'lambda1', {
            code: new lambda.InlineCode('exports.handler = async () => { console.log(\'hello world\'); };'),
            handler: 'index.handler',
            runtime: lambda.Runtime.NODEJS_10_X,
            currentVersionOptions: {
                provisionedConcurrentExecutions: 3
            }
        })

    }
}

Does not configure provisioned concurrency for the current version of the function.

export class LambdaAutoScalingStack extends cdk.Stack {
    constructor(scope: cdk.App, id: string) {
        super(scope, id);

        new lambda.Function(this, 'lambda1', {
            code: new lambda.InlineCode('exports.handler = async () => { console.log(\'hello world\'); };'),
            handler: 'index.handler',
            runtime: lambda.Runtime.NODEJS_10_X,
            currentVersionOptions: {
                provisionedConcurrentExecutions: 3
            }
        });
        fn.currentVersion;

    }
}

Does configure provisioned concurrency for the current version of the function.

Possible Solution

I'm not sure. Originally under #23002 the bug was fixed by implicitly calling currentVersion in the constructor if currentVersionOptions is not null, but as per #23636

this breaks the case where a user both:

  • Specifies currentVersionOptions
  • Never calls currentVersion but instead creates a Version object directly.

In that case, 2 Version resources are created, but the second one fails because Lambda will not allow creating a new Version if nothing changed since the last Version.

Additional Information/Context

This bug was previously lodged as #23002, however the fix provided under that issue was reverted by #23636 as it was flawed.

CDK CLI Version

2.96.0 (build e6322aa)

Framework Version

2.96.0

Node.js Version

v18.17.1

OS

Ubuntu (Windows Subsystem for Linux)

Language

Python

Language Version

3.9.7

Other information

No response

@SamStephens SamStephens added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 14, 2023
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Sep 14, 2023
@peterwoodworth peterwoodworth added p2 feature-request A feature should be added or improved. effort/medium Medium work item – several days of effort and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

2 participants