Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support AWS Lambdas ephemeral storage setting (#1120) #1125

Closed
wants to merge 10 commits into from
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,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 @@ -1005,7 +1006,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 @@ -905,6 +906,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 @@ -1167,6 +1169,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 @@ -2526,6 +2529,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 @@ -1165,6 +1165,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 @@ -1200,6 +1201,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 @@ -1351,6 +1353,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 @@ -1399,6 +1402,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