How to get the latest version of a lambda layer? #26670
-
I have a lambda layer with name, but the version may be published at some time. const latestLayer = lambda.LayerVersion.fromLayerVersionArn(this, 'mediaxFFmpegLayer', `arn:aws:lambda:${Aws.REGION}:${Aws.ACCOUNT_ID}:layer:layer-name`)` |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Answer: CDK won't look anything up in your AWS account regarding your Lambda Layer - so if you need a specific version of that layer, you will have to include that version in the arn that you pass in when importing. If you need some value (from AWS or elsewhere) for which there is no native CDK context provider, we recommend writing a separate script. The script should retrieve the value and write it to a file, then read that file in your CDK app. Run the script only when you want to refresh the stored value, not as part of your regular build process. |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
Answer: CDK won't look anything up in your AWS account regarding your Lambda Layer - so if you need a specific version of that layer, you will have to include that version in the arn that you pass in when importing.
If you need to programatically fetch the version of your arn, follow the following advice from our best practices page, see Commit cdk.context.json on this page for more information
If you need some value (from AWS or elsewhere) for which there is no native CDK context provider, we recommend writing a separate script. The script should retrieve the value and write it to a file, then read that file in your CDK app. Run the script only when you want to refresh the stored value, …