Skip to content

Commit

Permalink
fix(lambda): automatic currentVersion conflicts with explicit `Vers…
Browse files Browse the repository at this point in the history
…ion` 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*
  • Loading branch information
comcalvi committed Jan 11, 2023
1 parent e5b0230 commit de68652
Show file tree
Hide file tree
Showing 12 changed files with 0 additions and 597 deletions.
13 changes: 0 additions & 13 deletions packages/@aws-cdk/aws-lambda/README.md
Expand Up @@ -283,19 +283,6 @@ const version = new lambda.Version(this, 'MyVersion', {
});
```

Or setting the `currentVersionOptions` when creating a new lambda

```ts
new lambda.Function(this, 'MyVersionedLambda', {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'index.handler',
code: lambda.Code.fromAsset(path.join(__dirname, 'lambda-handler')),
currentVersionOptions: {
provisionedConcurrentExecutions: 3,
},
});
```

The major caveat to know here is that a function version must always point to a
specific 'version' of the function. When the function is modified, the version
will continue to point to the 'then version' of the function.
Expand Down
3 changes: 0 additions & 3 deletions packages/@aws-cdk/aws-lambda/lib/function.ts
Expand Up @@ -870,9 +870,6 @@ export class Function extends FunctionBase {
}

this.currentVersionOptions = props.currentVersionOptions;
if (props.currentVersionOptions) {
this.currentVersion;
}

if (props.filesystem) {
if (!props.vpc) {
Expand Down
25 changes: 0 additions & 25 deletions packages/@aws-cdk/aws-lambda/test/function.test.ts
Expand Up @@ -3047,31 +3047,6 @@ describe('function', () => {
});
});

test('Generates a version when currentVersionOptions is set', () => {
const stack = new cdk.Stack();

new lambda.Function(stack, 'MyLambda', {
code: new lambda.InlineCode('foo'),
handler: 'index.handler',
runtime: lambda.Runtime.NODEJS_14_X,
currentVersionOptions: {
provisionedConcurrentExecutions: 3,
},
});

Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Version', {
ProvisionedConcurrencyConfig: {
ProvisionedConcurrentExecutions: 3,
},
});

Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {
Code: { ZipFile: 'foo' },
Handler: 'index.handler',
Runtime: 'nodejs14.x',
});
});

test('adds ADOT instrumentation to a ZIP Lambda function', () => {
// GIVEN
const app = new cdk.App();
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit de68652

Please sign in to comment.