Skip to content

Commit f191bae

Browse files
feat: Added support for ephemeral storage (requires AWS provider version 4.8.0) (#291)
Co-authored-by: Anton Babenko <anton@antonbabenko.com>
1 parent e85bba8 commit f191bae

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ resource "aws_s3_bucket" "builds" {
148148
acl = "private"
149149
}
150150
151-
resource "aws_s3_bucket_object" "my_function" {
151+
resource "aws_s3_object" "my_function" {
152152
bucket = aws_s3_bucket.builds.id
153153
key = "${filemd5(local.my_function_source)}.zip"
154154
source = local.my_function_source
@@ -165,7 +165,7 @@ module "lambda_function_existing_package_s3" {
165165
create_package = false
166166
s3_existing_package = {
167167
bucket = aws_s3_bucket.builds.id
168-
key = aws_s3_bucket_object.my_function.id
168+
key = aws_s3_object.my_function.id
169169
}
170170
}
171171
```
@@ -602,7 +602,7 @@ Q4: What does this error mean - `"We currently do not support adding policies fo
602602
| Name | Version |
603603
|------|---------|
604604
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
605-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.69 |
605+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.8.0 |
606606
| <a name="requirement_external"></a> [external](#requirement\_external) | >= 1.0 |
607607
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 1.0 |
608608
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |
@@ -611,7 +611,7 @@ Q4: What does this error mean - `"We currently do not support adding policies fo
611611

612612
| Name | Version |
613613
|------|---------|
614-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.69 |
614+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.8.0 |
615615
| <a name="provider_external"></a> [external](#provider\_external) | >= 1.0 |
616616
| <a name="provider_local"></a> [local](#provider\_local) | >= 1.0 |
617617
| <a name="provider_null"></a> [null](#provider\_null) | >= 2.0 |
@@ -651,7 +651,7 @@ No modules.
651651
| [aws_lambda_permission.current_version_triggers](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource |
652652
| [aws_lambda_permission.unqualified_alias_triggers](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource |
653653
| [aws_lambda_provisioned_concurrency_config.current_version](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_provisioned_concurrency_config) | resource |
654-
| [aws_s3_bucket_object.lambda_package](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_object) | resource |
654+
| [aws_s3_object.lambda_package](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object) | resource |
655655
| [local_file.archive_plan](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
656656
| [null_resource.archive](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
657657
| [aws_arn.log_group_arn](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source |
@@ -710,6 +710,7 @@ No modules.
710710
| <a name="input_docker_pip_cache"></a> [docker\_pip\_cache](#input\_docker\_pip\_cache) | Whether to mount a shared pip cache folder into docker environment or not | `any` | `null` | no |
711711
| <a name="input_docker_with_ssh_agent"></a> [docker\_with\_ssh\_agent](#input\_docker\_with\_ssh\_agent) | Whether to pass SSH\_AUTH\_SOCK into docker environment or not | `bool` | `false` | no |
712712
| <a name="input_environment_variables"></a> [environment\_variables](#input\_environment\_variables) | A map that defines environment variables for the Lambda Function. | `map(string)` | `{}` | no |
713+
| <a name="input_ephemeral_storage_size"></a> [ephemeral\_storage\_size](#input\_ephemeral\_storage\_size) | Amount of ephemeral storage size (`/tmp`) in MB your Lambda Function can use at runtime. Valid value between 512 MB to 10,240 MB (10 GB). | `number` | `512` | no |
713714
| <a name="input_event_source_mapping"></a> [event\_source\_mapping](#input\_event\_source\_mapping) | Map of event source mapping | `any` | `{}` | no |
714715
| <a name="input_file_system_arn"></a> [file\_system\_arn](#input\_file\_system\_arn) | The Amazon Resource Name (ARN) of the Amazon EFS Access Point that provides access to the file system. | `string` | `null` | no |
715716
| <a name="input_file_system_local_mount_path"></a> [file\_system\_local\_mount\_path](#input\_file\_system\_local\_mount\_path) | The path where the function can access the file system, starting with /mnt/. | `string` | `null` | no |

examples/complete/main.tf

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ provider "aws" {
1717
module "lambda_function" {
1818
source = "../../"
1919

20-
function_name = "${random_pet.this.id}-lambda1"
21-
description = "My awesome lambda function"
22-
handler = "index.lambda_handler"
23-
runtime = "python3.8"
24-
architectures = ["x86_64"]
25-
publish = true
20+
function_name = "${random_pet.this.id}-lambda1"
21+
description = "My awesome lambda function"
22+
handler = "index.lambda_handler"
23+
runtime = "python3.8"
24+
ephemeral_storage_size = 10240
25+
architectures = ["x86_64"]
26+
publish = true
2627

2728
source_path = "${path.module}/../fixtures/python3.8-app1"
2829

examples/complete/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_version = ">= 0.13.1"
33

44
required_providers {
5-
aws = ">= 2.67"
5+
aws = ">= 4.8.0"
66
random = ">= 2"
77
}
88
}

main.tf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ locals {
1515
# s3_* - to get package from S3
1616
s3_bucket = var.s3_existing_package != null ? lookup(var.s3_existing_package, "bucket", null) : (var.store_on_s3 ? var.s3_bucket : null)
1717
s3_key = var.s3_existing_package != null ? lookup(var.s3_existing_package, "key", null) : (var.store_on_s3 ? var.s3_prefix != null ? format("%s%s", var.s3_prefix, replace(local.archive_filename_string, "/^.*//", "")) : replace(local.archive_filename_string, "/^\\.//", "") : null)
18-
s3_object_version = var.s3_existing_package != null ? lookup(var.s3_existing_package, "version_id", null) : (var.store_on_s3 ? try(aws_s3_bucket_object.lambda_package[0].version_id, null) : null)
18+
s3_object_version = var.s3_existing_package != null ? lookup(var.s3_existing_package, "version_id", null) : (var.store_on_s3 ? try(aws_s3_object.lambda_package[0].version_id, null) : null)
1919

2020
}
2121

@@ -37,6 +37,10 @@ resource "aws_lambda_function" "this" {
3737
package_type = var.package_type
3838
architectures = var.architectures
3939

40+
ephemeral_storage {
41+
size = var.ephemeral_storage_size
42+
}
43+
4044
filename = local.filename
4145
source_code_hash = var.ignore_source_code_hash ? null : (local.filename == null ? false : fileexists(local.filename)) && !local.was_missing ? filebase64sha256(local.filename) : null
4246

@@ -96,7 +100,7 @@ resource "aws_lambda_function" "this" {
96100
# When a lambda function is invoked, AWS creates the log group automatically if it doesn't exist yet.
97101
# Without the dependency, this can result in a race condition if the lambda function is invoked before
98102
# Terraform can create the log group.
99-
depends_on = [null_resource.archive, aws_s3_bucket_object.lambda_package, aws_cloudwatch_log_group.lambda]
103+
depends_on = [null_resource.archive, aws_s3_object.lambda_package, aws_cloudwatch_log_group.lambda]
100104
}
101105

102106
resource "aws_lambda_layer_version" "this" {
@@ -117,10 +121,10 @@ resource "aws_lambda_layer_version" "this" {
117121
s3_key = local.s3_key
118122
s3_object_version = local.s3_object_version
119123

120-
depends_on = [null_resource.archive, aws_s3_bucket_object.lambda_package]
124+
depends_on = [null_resource.archive, aws_s3_object.lambda_package]
121125
}
122126

123-
resource "aws_s3_bucket_object" "lambda_package" {
127+
resource "aws_s3_object" "lambda_package" {
124128
count = local.create && var.store_on_s3 && var.create_package ? 1 : 0
125129

126130
bucket = var.s3_bucket

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ variable "memory_size" {
103103
default = 128
104104
}
105105

106+
variable "ephemeral_storage_size" {
107+
description = "Amount of ephemeral storage (/tmp) in MB your Lambda Function can use at runtime. Valid value between 512 MB to 10,240 MB (10 GB)."
108+
type = number
109+
default = 512
110+
}
111+
106112
variable "publish" {
107113
description = "Whether to publish creation/change as new Lambda Function Version."
108114
type = bool

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 3.69"
7+
version = ">= 4.8.0"
88
}
99
external = {
1010
source = "hashicorp/external"

0 commit comments

Comments
 (0)