diff --git a/README.md b/README.md index ae4bcae0f..ef35205b0 100644 --- a/README.md +++ b/README.md @@ -833,6 +833,7 @@ to change Zappa's behavior. Use these at your own risk! "assume_policy": "my_assume_policy.json", // optional, IAM assume policy JSON file "attach_policy": "my_attach_policy.json", // optional, IAM attach policy JSON file "apigateway_policy": "my_apigateway_policy.json", // optional, API Gateway resource policy JSON file + "architecture": "x86_64", // optional, Set Lambda Architecture, defaults to x86_64. For Graviton 2 use: arm64 "async_source": "sns", // Source of async tasks. Defaults to "lambda" "async_resources": true, // Create the SNS topic and DynamoDB table to use. Defaults to true. "async_response_table": "your_dynamodb_table_name", // the DynamoDB table name to use for captured async responses; defaults to None (can't capture) diff --git a/zappa/cli.py b/zappa/cli.py index 546e4b19c..01ac3331a 100755 --- a/zappa/cli.py +++ b/zappa/cli.py @@ -126,6 +126,7 @@ class ZappaCLI: context_header_mappings = None tags = [] layers = None + architecture = None stage_name_env_pattern = re.compile("^[a-zA-Z0-9_]+$") @@ -911,6 +912,7 @@ def deploy(self, source_zip=None, docker_image_uri=None): use_alb=self.use_alb, layers=self.layers, concurrency=self.lambda_concurrency, + architecture=self.architecture, ) kwargs["function_name"] = self.lambda_name if docker_image_uri: @@ -1136,6 +1138,7 @@ def update(self, source_zip=None, no_upload=False, docker_image_uri=None): function_name=self.lambda_name, num_revisions=self.num_retained_versions, concurrency=self.lambda_concurrency, + architecture=self.architecture, ) if docker_image_uri: kwargs["docker_image_uri"] = docker_image_uri @@ -1172,6 +1175,8 @@ def update(self, source_zip=None, no_upload=False, docker_image_uri=None): aws_kms_key_arn=self.aws_kms_key_arn, layers=self.layers, wait=False, + architecture=self.architecture, + ) # Finally, delete the local copy our zip package @@ -2544,7 +2549,7 @@ def load_settings(self, settings_file=None, session=None): self.num_retained_versions = self.stage_config.get( "num_retained_versions", None ) - + self.architecture = [self.stage_config.get("architecture", "x86_64")] # Check for valid values of num_retained_versions if ( self.num_retained_versions is not None @@ -2615,6 +2620,9 @@ def load_settings(self, settings_file=None, session=None): # Additional tags self.tags = self.stage_config.get("tags", {}) + # Architectures + self.architecture = [self.stage_config.get("architecture", "x86_64")] + desired_role_name = self.lambda_name + "-ZappaLambdaExecutionRole" self.zappa = Zappa( boto_session=session, @@ -2627,6 +2635,7 @@ def load_settings(self, settings_file=None, session=None): tags=self.tags, endpoint_urls=self.stage_config.get("aws_endpoint_urls", {}), xray_tracing=self.xray_tracing, + architecture=self.architecture ) for setting in CUSTOM_SETTINGS: diff --git a/zappa/core.py b/zappa/core.py index 51fa74836..16db6d770 100644 --- a/zappa/core.py +++ b/zappa/core.py @@ -264,7 +264,7 @@ class Zappa: apigateway_policy = None cloudwatch_log_levels = ["OFF", "ERROR", "INFO"] xray_tracing = False - + architecture = None ## # Credentials ## @@ -284,6 +284,7 @@ def __init__( tags=(), endpoint_urls={}, xray_tracing=False, + architecture=None ): """ Instantiate this new Zappa instance, loading any custom credentials if necessary. @@ -316,13 +317,17 @@ def __init__( else: self.manylinux_suffix_start = "cp39" + if not self.architecture: + self.architecture = "x86_64" + # AWS Lambda supports manylinux1/2010, manylinux2014, and manylinux_2_24 manylinux_suffixes = ("_2_24", "2014", "2010", "1") self.manylinux_wheel_file_match = re.compile( - f'^.*{self.manylinux_suffix_start}-(manylinux_\d+_\d+_x86_64[.])?manylinux({"|".join(manylinux_suffixes)})_x86_64[.]whl$' + f'^.*{self.manylinux_suffix_start}-(manylinux_\d+_\d+_{self.architecture}[.])?manylinux({"|".join(manylinux_suffixes)})_{self.architecture}[.]whl$' ) self.manylinux_wheel_abi3_file_match = re.compile( - f'^.*cp3.-abi3-manylinux({"|".join(manylinux_suffixes)})_x86_64.whl$' + f'^.*cp3.-abi3-manylinux({"|".join(manylinux_suffixes)})_{self.architecture}.whl$' + ) self.endpoint_urls = endpoint_urls @@ -600,7 +605,7 @@ def create_lambda_zip( # Make sure that 'concurrent' is always forbidden. # https://github.com/Miserlou/Zappa/issues/827 - if not "concurrent" in exclude: + if "concurrent" not in exclude: exclude.append("concurrent") def splitpath(path): @@ -1177,6 +1182,7 @@ def create_lambda_function( layers=None, concurrency=None, docker_image_uri=None, + architecture=None ): """ Given a bucket and key (or a local path) of a valid Lambda-zip, a function name and a handler, register that Lambda function. @@ -1193,6 +1199,8 @@ def create_lambda_function( aws_kms_key_arn = "" if not layers: layers = [] + if not architecture: + self.architecture = "x86_64" kwargs = dict( FunctionName=function_name, @@ -1207,6 +1215,7 @@ def create_lambda_function( KMSKeyArn=aws_kms_key_arn, TracingConfig={"Mode": "Active" if self.xray_tracing else "PassThrough"}, Layers=layers, + Architectures=architecture, ) if not docker_image_uri: kwargs["Runtime"] = runtime @@ -1265,6 +1274,7 @@ def update_lambda_function( num_revisions=None, concurrency=None, docker_image_uri=None, + architecture=None ): """ Given a bucket and key (or a local path) of a valid Lambda-zip, a function name and a handler, update that Lambda function's code. @@ -1358,6 +1368,7 @@ def update_lambda_configuration( aws_kms_key_arn=None, layers=None, wait=True, + architecture=None ): """ Given an existing function ARN, update the configuration variables.