Node, can't use layer from arn for lambda
Having an existing layer in my account referencing it with cdk 1.31.0, to use in a new lambda does not work.
the Cloudformation error is not understandable, saying that the arn is not conforme, but the layer arn match the regex
Reproduction Steps
const myLayer = LayerVersion.fromLayerVersionArn(this, 'myLayer', arn:aws:lambda:eu-central-1:${this.account}:layer:mylayer:1`)
new lambda.Function(this, 'Lambda', { layers: [myLayer] [...] });`
Error Log
1 validation error detected: Value '[arn:aws:lambda:eu-central-1:XXXXMYACCOUNT:layer:mylayer:1"]' at 'layers' failed to satisfy constraint: Member must satisfy constraint: [Member must have length less than or equal to 140, Member must have length greater than or equal to 1, Member must satisfy regular expression pattern: (arn:[a-zA-Z0-9-]+:lambda:[a-zA-Z0-9-]+:\d{12}:layer:[a-zA-Z0-9-]+:[0-9]+)|(arn:[a-zA-Z0-9-]+:lambda:::awslayer:[a-zA-Z0-9-]+)] (Service: AWSLambdaInternal; Status Code: 400; Error Code: ValidationException; Request ID: bb1b3629-bbb6-43a7-94e8-4b84388c2d38)
Environment
- **CLI Version :aws-cli/1.15.4 Python/2.7.13 Linux/4.9.0-12-amd64 botocore/1.10.4
- **Framework Version:1.31.0
- **Language :typescript
This is :bug: Bug Report
Can you output the relevant parts of the template to make it easier to reproduce? On first look, it's hard to tell if this is CDK's fault or if we need to file a support ticket for Lambda :)
Here the relevant part :
LambdaD247545B: Type: AWS::Lambda::Function Properties: Layers: - arn:aws:lambda:eu-central-1:MYACCOUNTID:layer:oracle:1
according to https://docs.aws.amazon.com/fr_fr/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-layers seems ok, maybe it need quote ?
This is the typescript CDK app I have that does what you've suggested and I was able to successfully deploy this -
(using version 1.31.0)
#!/usr/bin/env node
import { App, Stack } from '@aws-cdk/core';
import { Function, Code, Runtime, LayerVersion } from '@aws-cdk/aws-lambda';
const app = new App();
const stack = new Stack(app, 'lambdalayerstack');
const layer = LayerVersion.fromLayerVersionArn(stack, 'layerversion', 'arn:aws:lambda:eu-west-1:664773442901:layer:test-layer:1');
new Function(stack, 'myfn', {
layers: [layer],
functionName: 'thisfunction',
code: Code.fromInline('foo'),
runtime: Runtime.NODEJS_12_X,
handler: 'index.handler',
});
The error message suggests that the ARN is malformed, but I can't see that to be the case. Make sure you're deploying to the same region as the layer, perhaps that is tripping this error message?
If you're still seeing this, could you provide a code snippet similar to the one I've provided above that's failing, that we can use to reproduce.
I got this error when accidentally passing the ARN of a layer rather than a layer version. Took me an embarrassing amount of time to notice that detail :)
Closing this issue for now since there hasn't been a response in a while. Feel free to reopen.