Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
Add support for layers
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondbutcher committed May 17, 2019
1 parent ca1a39e commit 23ff952
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function name unique per region, for example by setting
| function\_name | A unique name for your Lambda function (and related IAM resources) | string | n/a | yes |
| handler | The function entrypoint in your code | string | n/a | yes |
| lambda\_at\_edge | Set this to true if using Lambda@Edge, to enable publishing, limit the timeout, and allow edgelambda.amazonaws.com to invoke the function | string | `"false"` | no |
| layers | List of Lambda Layer Version ARNs to attach to your Lambda Function. | list | `<list>` | no |
| memory\_size | Amount of memory in MB your Lambda function can use at runtime | string | `"128"` | no |
| policy | An addional policy to attach to the Lambda function | string | `""` | no |
| publish | Whether to publish creation/change as new Lambda Function Version | string | `"false"` | no |
Expand Down
4 changes: 4 additions & 0 deletions lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ resource "aws_lambda_function" "lambda" {
memory_size = "${var.memory_size}"
reserved_concurrent_executions = "${var.reserved_concurrent_executions}"
runtime = "${var.runtime}"
layers = "${var.layers}"
timeout = "${local.timeout}"
publish = "${local.publish}"
tags = "${var.tags}"
Expand Down Expand Up @@ -57,6 +58,7 @@ resource "aws_lambda_function" "lambda_with_dl" {
memory_size = "${var.memory_size}"
reserved_concurrent_executions = "${var.reserved_concurrent_executions}"
runtime = "${var.runtime}"
layers = "${var.layers}"
timeout = "${local.timeout}"
publish = "${local.publish}"
tags = "${var.tags}"
Expand Down Expand Up @@ -85,6 +87,7 @@ resource "aws_lambda_function" "lambda_with_vpc" {
memory_size = "${var.memory_size}"
reserved_concurrent_executions = "${var.reserved_concurrent_executions}"
runtime = "${var.runtime}"
layers = "${var.layers}"
timeout = "${local.timeout}"
publish = "${local.publish}"
tags = "${var.tags}"
Expand Down Expand Up @@ -117,6 +120,7 @@ resource "aws_lambda_function" "lambda_with_dl_and_vpc" {
memory_size = "${var.memory_size}"
reserved_concurrent_executions = "${var.reserved_concurrent_executions}"
runtime = "${var.runtime}"
layers = "${var.layers}"
timeout = "${local.timeout}"
publish = "${local.publish}"
tags = "${var.tags}"
Expand Down
8 changes: 8 additions & 0 deletions tests/layers/lambda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import subprocess


def lambda_handler(event, context):

subprocess.run(['git'])

return 'test passed'
25 changes: 25 additions & 0 deletions tests/layers/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
terraform {
backend "local" {
path = "terraform.tfstate"
}
}

provider "aws" {
region = "eu-west-1"
}

module "lambda" {
source = "../../"

function_name = "terraform-aws-lambda-test-layers"
description = "Test layers in terraform-aws-lambda"
handler = "lambda.lambda_handler"
runtime = "python3.7"

layers = [
"arn:aws:lambda:::awslayer:AmazonLinux1803", # https://aws.amazon.com/blogs/compute/upcoming-updates-to-the-aws-lambda-execution-environment/
"arn:aws:lambda:eu-west-1:553035198032:layer:git:5", # https://github.com/lambci/git-lambda-layer
]

source_path = "${path.module}/lambda.py"
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ variable "runtime" {
type = "string"
}

variable "layers" {
description = "List of Lambda Layer Version ARNs to attach to your Lambda Function."
type = "list"
default = []
}

variable "timeout" {
description = "The amount of time your Lambda function had to run in seconds"
type = "string"
Expand Down

0 comments on commit 23ff952

Please sign in to comment.