Skip to content

Commit

Permalink
fix(lambda): deployment failure when layers are added to container fu…
Browse files Browse the repository at this point in the history
…nctions (#15037)

This change fixes #14143 by throwing an error during synthesis if layers are used in a container function.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
mprencipe authored Jun 10, 2021
1 parent f7f367f commit 8127cf2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/@aws-cdk/aws-lambda/lib/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,10 @@ export class Function extends FunctionBase {
this.runtime = props.runtime;

if (props.layers) {
if (props.runtime === Runtime.FROM_IMAGE) {
throw new Error('Layers are not supported for container image functions');
}

this.addLayers(...props.layers);
}

Expand Down
16 changes: 16 additions & 0 deletions packages/@aws-cdk/aws-lambda/test/function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,22 @@ describe('function', () => {
});
});
});

test('error when layers set in a container function', () => {
const stack = new cdk.Stack();
const bucket = new s3.Bucket(stack, 'Bucket');
const code = new lambda.S3Code(bucket, 'ObjectKey');

const layer = new lambda.LayerVersion(stack, 'Layer', {
code,
});

expect(() => new lambda.DockerImageFunction(stack, 'MyLambda', {
code: lambda.DockerImageCode.fromImageAsset(path.join(__dirname, 'docker-lambda-handler')),
layers: [layer],
})).toThrow(/Layers are not supported for container image functions/);
});

});

function newTestLambda(scope: constructs.Construct) {
Expand Down

0 comments on commit 8127cf2

Please sign in to comment.