question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Node, can't use layer from arn for lambda

See original GitHub issue

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 Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
nija-atcommented, Apr 16, 2020

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.

1reaction
ewahl-alcommented, Apr 22, 2020

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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using layers with your Lambda function - AWS Documentation
Configuring layers with the console · Open the Functions page of the Lambda console. · Choose the function to configure. · Under Layers,...
Read more >
Lambda function using Layers - node.js - Stack Overflow
On my Lambda function I have set to use the Layer with version specified via AWS GUI. Code on my Lambda function var...
Read more >
Layers in Lambda function for Node JS | by Shruti Tirpude
Layers in Lambda functions should be simple to use. I always thought just zip the node modules and upload it and it should...
Read more >
AWS Lambda Native Tracing for Node.js - IBM
That is, the pattern is arn:aws:lambda:${region}:410797082306:layer:instana-nodejs:${layer-version} . Please make sure to always use the latest versions and ...
Read more >
Use AWS Lambda layers for your Node.js app
Another benefit of using the Lambda layer is that the deployment size of your package can be 250Mb whereas it can not exceed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found