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

Add Support for Graviton 2 / ARM Architectures #1057

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,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": "arm64", // 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
9 changes: 9 additions & 0 deletions 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
architectures = []

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,
architectures=self.architectures,
)
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,
architectures=self.architectures,
)
if docker_image_uri:
kwargs["docker_image_uri"] = docker_image_uri
Expand Down Expand Up @@ -1172,6 +1175,7 @@ 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,
architectures=self.architectures,
)

# Finally, delete the local copy our zip package
Expand Down Expand Up @@ -2537,6 +2541,7 @@ def load_settings(self, settings_file=None, session=None):
self.num_retained_versions = self.stage_config.get(
"num_retained_versions", None
)
self.architectures = [self.stage_config.get("architectures", "x86_64")]

# Check for valid values of num_retained_versions
if (
Expand Down Expand Up @@ -2608,6 +2613,9 @@ def load_settings(self, settings_file=None, session=None):
# Additional tags
self.tags = self.stage_config.get("tags", {})

# Architectures
self.architectures = [self.stage_config.get("architectures", "x86_64")]

desired_role_name = self.lambda_name + "-ZappaLambdaExecutionRole"
self.zappa = Zappa(
boto_session=session,
Expand All @@ -2620,6 +2628,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,
architectures=self.architectures
)

for setting in CUSTOM_SETTINGS:
Expand Down
17 changes: 14 additions & 3 deletions zappa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class Zappa:
apigateway_policy = None
cloudwatch_log_levels = ["OFF", "ERROR", "INFO"]
xray_tracing = False
architectures = []

##
# Credentials
Expand All @@ -284,6 +285,7 @@ def __init__(
tags=(),
endpoint_urls={},
xray_tracing=False,
architectures=[],
):
"""
Instantiate this new Zappa instance, loading any custom credentials if necessary.
Expand Down Expand Up @@ -316,13 +318,16 @@ def __init__(
else:
self.manylinux_suffix_start = "cp39"

if len(self.architectures) == 0:
self.architectures.append("x86_64")

# AWS Lambda supports manylinux1/2010 and manylinux2014
manylinux_suffixes = ("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.architectures[0]}[.])?manylinux({"|".join(manylinux_suffixes)})_{self.architectures[0]}[.]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.architectures[0]}.whl$'
)

self.endpoint_urls = endpoint_urls
Expand Down Expand Up @@ -960,7 +965,7 @@ def get_cached_manylinux_wheel(
else:
# Check if we already have a cached copy
wheel_name = re.sub("[^\w\d.]+", "_", package_name, re.UNICODE)
wheel_file = f"{wheel_name}-{package_version}-*_x86_64.whl"
wheel_file = f"{wheel_name}-{package_version}-*_{self.architectures[0]}.whl"
wheel_path = os.path.join(cached_wheels_dir, wheel_file)

for pathname in glob.iglob(wheel_path):
Expand Down Expand Up @@ -1176,6 +1181,7 @@ def create_lambda_function(
layers=None,
concurrency=None,
docker_image_uri=None,
architectures=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 @@ -1192,6 +1198,8 @@ def create_lambda_function(
aws_kms_key_arn = ""
if not layers:
layers = []
if not architectures:
self.architectures = ["x86_64"]

kwargs = dict(
FunctionName=function_name,
Expand All @@ -1206,6 +1214,7 @@ def create_lambda_function(
KMSKeyArn=aws_kms_key_arn,
TracingConfig={"Mode": "Active" if self.xray_tracing else "PassThrough"},
Layers=layers,
Architectures=architectures,
)
if not docker_image_uri:
kwargs["Runtime"] = runtime
Expand Down Expand Up @@ -1264,6 +1273,7 @@ def update_lambda_function(
num_revisions=None,
concurrency=None,
docker_image_uri=None,
architectures=[],
):
"""
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 @@ -1357,6 +1367,7 @@ def update_lambda_configuration(
aws_kms_key_arn=None,
layers=None,
wait=True,
architectures=[],
):
"""
Given an existing function ARN, update the configuration variables.
Expand Down