15

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"
}

1 Answer 1

14

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.