Skip to content

Commit de68652

Browse files
authored
fix(lambda): automatic currentVersion conflicts with explicit Version resource (#23636)
In #23225, we automatically created a `currentVersion` Version object if the `currentVersionOptions` property was specified. However, 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. Reverting that change. ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Construct Runtime Dependencies: * [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent e5b0230 commit de68652

12 files changed

+0
-597
lines changed

packages/@aws-cdk/aws-lambda/README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -283,19 +283,6 @@ const version = new lambda.Version(this, 'MyVersion', {
283283
});
284284
```
285285

286-
Or setting the `currentVersionOptions` when creating a new lambda
287-
288-
```ts
289-
new lambda.Function(this, 'MyVersionedLambda', {
290-
runtime: lambda.Runtime.NODEJS_18_X,
291-
handler: 'index.handler',
292-
code: lambda.Code.fromAsset(path.join(__dirname, 'lambda-handler')),
293-
currentVersionOptions: {
294-
provisionedConcurrentExecutions: 3,
295-
},
296-
});
297-
```
298-
299286
The major caveat to know here is that a function version must always point to a
300287
specific 'version' of the function. When the function is modified, the version
301288
will continue to point to the 'then version' of the function.

packages/@aws-cdk/aws-lambda/lib/function.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,9 +870,6 @@ export class Function extends FunctionBase {
870870
}
871871

872872
this.currentVersionOptions = props.currentVersionOptions;
873-
if (props.currentVersionOptions) {
874-
this.currentVersion;
875-
}
876873

877874
if (props.filesystem) {
878875
if (!props.vpc) {

packages/@aws-cdk/aws-lambda/test/function.test.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3047,31 +3047,6 @@ describe('function', () => {
30473047
});
30483048
});
30493049

3050-
test('Generates a version when currentVersionOptions is set', () => {
3051-
const stack = new cdk.Stack();
3052-
3053-
new lambda.Function(stack, 'MyLambda', {
3054-
code: new lambda.InlineCode('foo'),
3055-
handler: 'index.handler',
3056-
runtime: lambda.Runtime.NODEJS_14_X,
3057-
currentVersionOptions: {
3058-
provisionedConcurrentExecutions: 3,
3059-
},
3060-
});
3061-
3062-
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Version', {
3063-
ProvisionedConcurrencyConfig: {
3064-
ProvisionedConcurrentExecutions: 3,
3065-
},
3066-
});
3067-
3068-
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {
3069-
Code: { ZipFile: 'foo' },
3070-
Handler: 'index.handler',
3071-
Runtime: 'nodejs14.x',
3072-
});
3073-
});
3074-
30753050
test('adds ADOT instrumentation to a ZIP Lambda function', () => {
30763051
// GIVEN
30773052
const app = new cdk.App();

packages/@aws-cdk/aws-lambda/test/integ.current-version-options.js.snapshot/CurrentVersionOptionsDefaultTestDeployAssertF66C8354.assets.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/@aws-cdk/aws-lambda/test/integ.current-version-options.js.snapshot/CurrentVersionOptionsDefaultTestDeployAssertF66C8354.template.json

Lines changed: 0 additions & 36 deletions
This file was deleted.

packages/@aws-cdk/aws-lambda/test/integ.current-version-options.js.snapshot/cdk.out

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/@aws-cdk/aws-lambda/test/integ.current-version-options.js.snapshot/current-version-options.assets.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/@aws-cdk/aws-lambda/test/integ.current-version-options.js.snapshot/current-version-options.template.json

Lines changed: 0 additions & 99 deletions
This file was deleted.

packages/@aws-cdk/aws-lambda/test/integ.current-version-options.js.snapshot/integ.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/@aws-cdk/aws-lambda/test/integ.current-version-options.js.snapshot/manifest.json

Lines changed: 0 additions & 123 deletions
This file was deleted.

0 commit comments

Comments
 (0)