Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use an AWS provided lambda layer in Terraform?

I am trying to run a python function on an AWS Lambda layer, I don't find any documentation on terraform to use an AWS provided lambda layer. How do I use AWS Provided lambda layer AWSLambda-Python27-SciPy1x and runtime Python 2.7?

#----compute/lambda.tf----
data "archive_file" "lambda_zip" {
    type          = "zip"
    source_file   = "index.py"
    output_path   = "check_foo.zip"
}

resource "aws_lambda_function" "check_foo" {
  filename         = "check_foo.zip"
  function_name    = "checkFoo"
  role             = "${aws_iam_role.iam_for_lambda_tf.arn}"
  handler          = "index.handler"
  source_code_hash = "${data.archive_file.lambda_zip.output_base64sha256}"

  # i want to use lambda layer - AWSLambda-Python27-SciPy1x and run this function on it
  runtime          = "python2.7"
}
like image 859
mellifluous Avatar asked Jan 18 '26 03:01

mellifluous


1 Answers

You have to specify lambda layers as ARNs in terraform using layers parameter:

layers - (Optional) List of Lambda Layer Version ARNs (maximum of 5) to attach to your Lambda Function.

Using the following syntax in terraform:

layers = ["layer-arn"]

For example, the ARN for AWSLambda-Python27-SciPy1x in us-east-1 region is:

arn:aws:lambda:us-east-1:668099181075:layer:AWSLambda-Python27-SciPy1x:24

If you not sure what is your ARN, you can create a dummy a Python 2.7 lambda function, add AWS layer AWSLambda-Python27-SciPy1x layer, and the console will give you its ARN.

like image 195
Marcin Avatar answered Jan 19 '26 20:01

Marcin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!