Skip to content

Commit

Permalink
Merge pull request #2 from gbartosz/feature/ephemeral_storage
Browse files Browse the repository at this point in the history
Support AWS Lambdas ephemeral storage setting (zappa#1120)
  • Loading branch information
wangsha authored Jun 15, 2022
2 parents 9c357d9 + 5653c76 commit d11892b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ to change Zappa's behavior. Use these at your own risk!
"log_level": "DEBUG", // Set the Zappa log level. Can be one of CRITICAL, ERROR, WARNING, INFO and DEBUG. Default: DEBUG
"manage_roles": true, // Have Zappa automatically create and define IAM execution roles and policies. Default true. If false, you must define your own IAM Role and role_name setting.
"memory_size": 512, // Lambda function memory in MB. Default 512.
"ephemeral_storage": { "Size": 512 }, // Lambda ephemeral storage memory in MB. Default 512. Max 10240.
"num_retained_versions":null, // Indicates the number of old versions to retain for the lambda. If absent, keeps all the versions of the function.
"payload_compression": true, // Whether or not to enable API gateway payload compression (default: true)
"payload_minimum_compression_size": 0, // The threshold size (in bytes) below which payload compression will not be applied (default: 0)
Expand Down Expand Up @@ -1006,7 +1007,7 @@ You can also simply handle CORS directly in your application. Your web framework

### Large Projects

AWS currently limits Lambda zip sizes to 50 megabytes. If your project is larger than that, set `slim_handler: true` in your `zappa_settings.json`. In this case, your fat application package will be replaced with a small handler-only package. The handler file then pulls the rest of the large project down from S3 at run time! The initial load of the large project may add to startup overhead, but the difference should be minimal on a warm lambda function. Note that this will also eat into the storage space of your application function. Note that AWS currently [limits](https://docs.aws.amazon.com/lambda/latest/dg/limits.html) the `/tmp` directory storage to 512 MB, so your project must still be smaller than that.
AWS currently limits Lambda zip sizes to 50 megabytes. If your project is larger than that, set `slim_handler: true` in your `zappa_settings.json`. In this case, your fat application package will be replaced with a small handler-only package. The handler file then pulls the rest of the large project down from S3 at run time! The initial load of the large project may add to startup overhead, but the difference should be minimal on a warm lambda function. Note that this will also eat into the storage space of your application function. Note that AWS [supports](https://aws.amazon.com/blogs/compute/using-larger-ephemeral-storage-for-aws-lambda/) custom `/tmp` directory storage size in a range of 512 - 10240 MB. Use `ephemeral_storage` in `zappa_settings.json` to adjust to your needs if your project is larger than default 512 MB.

### Enabling Bash Completion

Expand Down
6 changes: 6 additions & 0 deletions zappa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class ZappaCLI:
handler_path = None
vpc_config = None
memory_size = None
ephemeral_storage = None
use_apigateway = None
lambda_handler = None
django_settings = None
Expand Down Expand Up @@ -906,6 +907,7 @@ def deploy(self, source_zip=None, docker_image_uri=None):
dead_letter_config=self.dead_letter_config,
timeout=self.timeout_seconds,
memory_size=self.memory_size,
ephemeral_storage=self.ephemeral_storage,
runtime=self.runtime,
aws_environment_variables=self.aws_environment_variables,
aws_kms_key_arn=self.aws_kms_key_arn,
Expand Down Expand Up @@ -1170,6 +1172,7 @@ def update(self, source_zip=None, no_upload=False, docker_image_uri=None):
vpc_config=self.vpc_config,
timeout=self.timeout_seconds,
memory_size=self.memory_size,
ephemeral_storage=self.ephemeral_storage,
runtime=self.runtime,
aws_environment_variables=self.aws_environment_variables,
aws_kms_key_arn=self.aws_kms_key_arn,
Expand Down Expand Up @@ -2531,6 +2534,9 @@ def load_settings(self, settings_file=None, session=None):
)
self.vpc_config = self.stage_config.get("vpc_config", {})
self.memory_size = self.stage_config.get("memory_size", 512)
self.ephemeral_storage = self.stage_config.get(
"ephemeral_storage", {"Size": 512}
)
self.app_function = self.stage_config.get("app_function", None)
self.exception_handler = self.stage_config.get("exception_handler", None)
self.aws_region = self.stage_config.get("aws_region", None)
Expand Down
4 changes: 4 additions & 0 deletions zappa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,7 @@ def create_lambda_function(
description="Zappa Deployment",
timeout=30,
memory_size=512,
ephemeral_storage={"Size": 512},
publish=True,
vpc_config=None,
dead_letter_config=None,
Expand Down Expand Up @@ -1211,6 +1212,7 @@ def create_lambda_function(
Description=description,
Timeout=timeout,
MemorySize=memory_size,
EphemeralStorage=ephemeral_storage,
Publish=publish,
VpcConfig=vpc_config,
DeadLetterConfig=dead_letter_config,
Expand Down Expand Up @@ -1363,6 +1365,7 @@ def update_lambda_configuration(
description="Zappa Deployment",
timeout=30,
memory_size=512,
ephemeral_storage={"Size": 512},
publish=True,
vpc_config=None,
runtime="python3.6",
Expand Down Expand Up @@ -1411,6 +1414,7 @@ def update_lambda_configuration(
"Description": description,
"Timeout": timeout,
"MemorySize": memory_size,
"EphemeralStorage": ephemeral_storage,
"VpcConfig": vpc_config,
"Environment": {"Variables": aws_environment_variables},
"KMSKeyArn": aws_kms_key_arn,
Expand Down

0 comments on commit d11892b

Please sign in to comment.