(lambda): Remove requirement to call currentVersion in order for currentVersionOptions to take effect
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### 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 https://github.com/aws/aws-cdk/issues/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 https://github.com/aws/aws-cdk/issues/23002 the bug was fixed by implicitly calling `currentVersion` in the constructor if `currentVersionOptions` is not `null`, but as per https://github.com/aws/aws-cdk/pull/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 https://github.com/aws/aws-cdk/issues/23002, however the fix provided under that issue was reverted by https://github.com/aws/aws-cdk/pull/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_
Contributor guide
Research direction
Start at the Function currentVersion entry point and trace how currentVersionOptions is handled during construct creation. Reproduce the issue with cdk diff, then compare behavior when currentVersion is accessed and when a Version is created directly. Done means the options take effect without requiring currentVersion, while avoiding duplicate Version resources.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100