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

Commit 23ff952

Browse files
Add support for layers
1 parent ca1a39e commit 23ff952

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ function name unique per region, for example by setting
8080
| function\_name | A unique name for your Lambda function (and related IAM resources) | string | n/a | yes |
8181
| handler | The function entrypoint in your code | string | n/a | yes |
8282
| 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 |
83+
| layers | List of Lambda Layer Version ARNs to attach to your Lambda Function. | list | `<list>` | no |
8384
| memory\_size | Amount of memory in MB your Lambda function can use at runtime | string | `"128"` | no |
8485
| policy | An addional policy to attach to the Lambda function | string | `""` | no |
8586
| publish | Whether to publish creation/change as new Lambda Function Version | string | `"false"` | no |

lambda.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ resource "aws_lambda_function" "lambda" {
1313
memory_size = "${var.memory_size}"
1414
reserved_concurrent_executions = "${var.reserved_concurrent_executions}"
1515
runtime = "${var.runtime}"
16+
layers = "${var.layers}"
1617
timeout = "${local.timeout}"
1718
publish = "${local.publish}"
1819
tags = "${var.tags}"
@@ -57,6 +58,7 @@ resource "aws_lambda_function" "lambda_with_dl" {
5758
memory_size = "${var.memory_size}"
5859
reserved_concurrent_executions = "${var.reserved_concurrent_executions}"
5960
runtime = "${var.runtime}"
61+
layers = "${var.layers}"
6062
timeout = "${local.timeout}"
6163
publish = "${local.publish}"
6264
tags = "${var.tags}"
@@ -85,6 +87,7 @@ resource "aws_lambda_function" "lambda_with_vpc" {
8587
memory_size = "${var.memory_size}"
8688
reserved_concurrent_executions = "${var.reserved_concurrent_executions}"
8789
runtime = "${var.runtime}"
90+
layers = "${var.layers}"
8891
timeout = "${local.timeout}"
8992
publish = "${local.publish}"
9093
tags = "${var.tags}"
@@ -117,6 +120,7 @@ resource "aws_lambda_function" "lambda_with_dl_and_vpc" {
117120
memory_size = "${var.memory_size}"
118121
reserved_concurrent_executions = "${var.reserved_concurrent_executions}"
119122
runtime = "${var.runtime}"
123+
layers = "${var.layers}"
120124
timeout = "${local.timeout}"
121125
publish = "${local.publish}"
122126
tags = "${var.tags}"

tests/layers/lambda.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import subprocess
2+
3+
4+
def lambda_handler(event, context):
5+
6+
subprocess.run(['git'])
7+
8+
return 'test passed'

tests/layers/main.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
terraform {
2+
backend "local" {
3+
path = "terraform.tfstate"
4+
}
5+
}
6+
7+
provider "aws" {
8+
region = "eu-west-1"
9+
}
10+
11+
module "lambda" {
12+
source = "../../"
13+
14+
function_name = "terraform-aws-lambda-test-layers"
15+
description = "Test layers in terraform-aws-lambda"
16+
handler = "lambda.lambda_handler"
17+
runtime = "python3.7"
18+
19+
layers = [
20+
"arn:aws:lambda:::awslayer:AmazonLinux1803", # https://aws.amazon.com/blogs/compute/upcoming-updates-to-the-aws-lambda-execution-environment/
21+
"arn:aws:lambda:eu-west-1:553035198032:layer:git:5", # https://github.com/lambci/git-lambda-layer
22+
]
23+
24+
source_path = "${path.module}/lambda.py"
25+
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ variable "runtime" {
2525
type = "string"
2626
}
2727

28+
variable "layers" {
29+
description = "List of Lambda Layer Version ARNs to attach to your Lambda Function."
30+
type = "list"
31+
default = []
32+
}
33+
2834
variable "timeout" {
2935
description = "The amount of time your Lambda function had to run in seconds"
3036
type = "string"

0 commit comments

Comments
 (0)