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

PR-1123 Add Support for Graviton 2 / ARM Architecture (conflict fix) #1209

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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 @@ -891,6 +891,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)
Expand Down
10 changes: 9 additions & 1 deletion zappa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class ZappaCLI:
additional_text_mimetypes = None
tags = []
layers = None
architecture = None

stage_name_env_pattern = re.compile("^[a-zA-Z0-9_]+$")

Expand Down Expand Up @@ -818,6 +819,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 @@ -1022,6 +1024,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 @@ -1058,6 +1061,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,
architecture=self.architecture,
)

# Finally, delete the local copy our zip package
Expand Down Expand Up @@ -2248,7 +2252,7 @@ def load_settings(self, settings_file=None, session=None):
self.dead_letter_config = {"TargetArn": dead_letter_arn} if dead_letter_arn else {}
self.cognito = self.stage_config.get("cognito", None)
self.num_retained_versions = self.stage_config.get("num_retained_versions", None)

self.architecture = [self.stage_config.get("architecture", "x86_64")]
gaborschulz marked this conversation as resolved.
Show resolved Hide resolved
# Check for valid values of num_retained_versions
if self.num_retained_versions is not None and type(self.num_retained_versions) is not int:
raise ClickException(
Expand Down Expand Up @@ -2305,6 +2309,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")]

gaborschulz marked this conversation as resolved.
Show resolved Hide resolved
desired_role_name = self.lambda_name + "-ZappaLambdaExecutionRole"
self.zappa = Zappa(
boto_session=session,
Expand All @@ -2317,6 +2324,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
20 changes: 17 additions & 3 deletions zappa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class Zappa:
apigateway_policy = None
cloudwatch_log_levels = ["OFF", "ERROR", "INFO"]
xray_tracing = False

architecture = None
##
# Credentials
##
Expand All @@ -285,6 +285,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 @@ -315,13 +316,18 @@ def __init__(
else:
self.manylinux_suffix_start = "cp39"

self.architecture = architecture
gaborschulz marked this conversation as resolved.
Show resolved Hide resolved
gaborschulz marked this conversation as resolved.
Show resolved Hide resolved
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(
rf'^.*{self.manylinux_suffix_start}-(manylinux_\d+_\d+_x86_64[.])?manylinux({"|".join(manylinux_suffixes)})_x86_64[.]whl$' # noqa: E501
rf"^.*{self.manylinux_suffix_start}-(manylinux_\d+_\d+_{self.architecture}"
rf'[.])?manylinux({"|".join(manylinux_suffixes)})_{self.architecture}[.]whl$'
)
self.manylinux_wheel_abi3_file_match = re.compile(
rf'^.*cp3.-abi3-manylinux({"|".join(manylinux_suffixes)})_x86_64.whl$'
f'^.*cp3.-abi3-manylinux({"|".join(manylinux_suffixes)})_{self.architecture}.whl$'
gaborschulz marked this conversation as resolved.
Show resolved Hide resolved
)

self.endpoint_urls = endpoint_urls
Expand Down Expand Up @@ -1120,6 +1126,7 @@ def create_lambda_function(
layers=None,
concurrency=None,
docker_image_uri=None,
architecture=None,
gaborschulz marked this conversation as resolved.
Show resolved Hide resolved
):
"""
Given a bucket and key (or a local path) of a valid Lambda-zip,
Expand All @@ -1137,6 +1144,8 @@ def create_lambda_function(
aws_kms_key_arn = ""
if not layers:
layers = []
if not architecture:
architecture = self.architecture

kwargs = dict(
FunctionName=function_name,
Expand All @@ -1151,6 +1160,9 @@ 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 @@ -1209,6 +1221,7 @@ def update_lambda_function(
num_revisions=None,
concurrency=None,
docker_image_uri=None,
architecture=None,
gaborschulz marked this conversation as resolved.
Show resolved Hide resolved
):
"""
Given a bucket and key (or a local path) of a valid Lambda-zip,
Expand Down Expand Up @@ -1299,6 +1312,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