How to import an AWS Managed Lambda Layer in Terrafrom

Viewed 359

AWS manages a layer called AWSDataWrangler-Python38. How do I import it into my Terraform Code. I tried using the Layer Module

resource "aws_lambda_layer_version" "lambda_layer" {
  layer_name = "AWSDataWrangler-Python39"
  compatible_runtimes = ["python3.9"]
}

It throws an error to specify filename, but there is no file for this layer since it is managed by AWS and it is not a custom layer

1 Answers

You can not import a resource which is not managed by you.

Since this is a layer managed by AWS, there is a public list with all the ARN numbers available for this layer: https://aws-data-wrangler.readthedocs.io/en/stable/layers.html

If you want to use this layer for a Lambda in your Terraform code, you will have to take an ARN from this list and simply hard-code it (or provide it externally with a variable). For example:

resource "aws_lambda_function" "lambda" {
  function_name    = "MyFunction"
  ...

  layers = [
    "arn:aws:lambda:${var.region}:336392948345:layer:AWSDataWrangler-Python39:6"
  ]
}
Related