Skip to content

Commit

Permalink
Add Support for Graviton 2 / ARM Architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
DS992 committed Apr 14, 2022
1 parent a1e842c commit 8d4c9f2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
"architectures": "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)
Expand Down
11 changes: 10 additions & 1 deletion zappa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_]+$")

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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:
Expand Down
19 changes: 15 additions & 4 deletions zappa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class Zappa:
apigateway_policy = None
cloudwatch_log_levels = ["OFF", "ERROR", "INFO"]
xray_tracing = False

architecture = None
##
# Credentials
##
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 8d4c9f2

Please sign in to comment.