Skip to content

Native build refactoring and MakeFiles logic removal #197

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

Open
wants to merge 3 commits into
base: lszecsi/refactoring-docstr
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions .github/workflows/test-on-push-and-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,36 @@ jobs:
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Run 'pr' target
run: make pr
run: poetry run poe pr

alpine:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Run alpine integration tests
run: DISTRO=alpine make test-integ
run: DISTRO=alpine poetry run poe test-integ

amazonlinux:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Run amazonlinux integration tests
run: DISTRO=amazonlinux make test-integ
run: DISTRO=amazonlinux poetry run poe test-integ

debian:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Run debian integration tests
run: DISTRO=debian make test-integ
run: DISTRO=debian poetry run poe test-integ

ubuntu:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Run ubuntu integration tests
run: DISTRO=ubuntu make test-integ
run: DISTRO=ubuntu poetry run poe test-integ
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,6 @@ deps/curl-*/

# local build artifacts
build-artifacts

# native wheels used for testing the separation of the native build
native-wheels/
13 changes: 0 additions & 13 deletions .pre-commit-config.yaml

This file was deleted.

21 changes: 7 additions & 14 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
FROM python:3.9-alpine AS build-image

# Install build dependencies
RUN apk add --no-cache \
build-base \
libtool \
autoconf \
automake \
elfutils-dev \
make \
cmake \
libcurl \
curl \
libstdc++ \
binutils

RUN apk add --no-cache curl make

# Install native wheel dependency
COPY native-wheels/*.whl /tmp/native-wheels/
RUN pip install /tmp/native-wheels/*.whl

# Build awslambdaric
ARG RIC_BUILD_DIR="/home/build/"
Expand All @@ -22,7 +15,7 @@ COPY . .
RUN pip install setuptools
RUN curl -sSL https://install.python-poetry.org | python3 - && \
ln -s /root/.local/bin/poetry /usr/local/bin/poetry
RUN make init build
RUN poetry install && poetry run poe build

# Keep the built wheel accessible
CMD ["sh", "-c", "echo 'Build complete. Wheel available in /home/build/dist/'"]
4 changes: 4 additions & 0 deletions Dockerfile.rie
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ RUN apk add --no-cache libstdc++ curl
RUN curl -Lo /usr/local/bin/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie && \
chmod +x /usr/local/bin/aws-lambda-rie

# Install native wheel dependency first
ADD native-wheels/*.whl /tmp/native/
RUN pip install /tmp/native/*.whl

# Add the pre-built wheel
ADD build-artifacts/*.whl /tmp/

Expand Down
91 changes: 0 additions & 91 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion awslambdaric/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved."""

__version__ = "3.1.1"
__version__ = "3.0.2"
49 changes: 26 additions & 23 deletions awslambdaric/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import sys
import time
import traceback
from typing import Any, Optional, List

from .lambda_context import LambdaContext
from .lambda_runtime_client import LambdaRuntimeClient
from .lambda_runtime_exception import FaultException
from .interfaces import RuntimeClientProtocol, LogSinkProtocol
from .lambda_runtime_log_utils import (
_DATETIME_FORMAT,
_DEFAULT_FRAME_TYPE,
Expand Down Expand Up @@ -152,18 +154,18 @@ def log_error(error_result, log_sink):


def handle_event_request(
lambda_runtime_client,
request_handler,
invoke_id,
event_body,
content_type,
client_context_json,
cognito_identity_json,
invoked_function_arn,
epoch_deadline_time_in_ms,
tenant_id,
log_sink,
):
lambda_runtime_client: RuntimeClientProtocol,
request_handler: Any,
invoke_id: Optional[str],
event_body: Any,
content_type: Optional[str],
client_context_json: Optional[str],
cognito_identity_json: Optional[str],
invoked_function_arn: Optional[str],
epoch_deadline_time_in_ms: Optional[str],
tenant_id: Optional[str],
log_sink: LogSinkProtocol,
) -> None:
"""Handle Lambda event request."""
error_result = None
try:
Expand Down Expand Up @@ -228,12 +230,12 @@ def parse_json_header(header, name):


def create_lambda_context(
client_context_json,
cognito_identity_json,
epoch_deadline_time_in_ms,
invoke_id,
invoked_function_arn,
tenant_id,
client_context_json: Optional[str],
cognito_identity_json: Optional[str],
epoch_deadline_time_in_ms: Optional[str],
invoke_id: Optional[str],
invoked_function_arn: Optional[str],
tenant_id: Optional[str],
):
"""Create Lambda context object."""
client_context = None
Expand Down Expand Up @@ -390,7 +392,7 @@ def writelines(self, msgs):
self.stream.flush()


class StandardLogSink(object):
class StandardLogSink:
"""Standard log sink."""

def __init__(self):
Expand All @@ -403,11 +405,11 @@ def __enter__(self):
def __exit__(self, exc_type, exc_value, exc_tb):
pass

def log(self, msg, frame_type=None):
def log(self, msg: str, frame_type: Optional[bytes] = None) -> None:
"""Log message to stdout."""
sys.stdout.write(msg)

def log_error(self, message_lines):
def log_error(self, message_lines: List[str]) -> None:
"""Log error message to stdout."""
error_message = ERROR_LOG_LINE_TERMINATE.join(message_lines) + "\n"
sys.stdout.write(error_message)
Expand All @@ -432,6 +434,7 @@ class FramedTelemetryLogSink(object):
def __init__(self, fd):
"""Initialize framed telemetry log sink."""
self.fd = int(fd)
self.file: Any = None

def __enter__(self):
self.file = os.fdopen(self.fd, "wb", 0)
Expand All @@ -440,7 +443,7 @@ def __enter__(self):
def __exit__(self, exc_type, exc_value, exc_tb):
self.file.close()

def log(self, msg, frame_type=None):
def log(self, msg: str, frame_type: Optional[bytes] = None) -> None:
"""Log message with frame type."""
encoded_msg = msg.encode("utf8")

Expand All @@ -453,7 +456,7 @@ def log(self, msg, frame_type=None):
)
self.file.write(log_msg)

def log_error(self, message_lines):
def log_error(self, message_lines: List[str]) -> None:
"""Log error message."""
error_message = "\n".join(message_lines)
self.log(
Expand Down
33 changes: 33 additions & 0 deletions awslambdaric/interfaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Protocol interfaces for AWS Lambda Runtime Interface Client."""

from typing import Protocol, Any, Dict, Tuple, Optional, List


class RuntimeClientProtocol(Protocol):
"""Protocol for Lambda runtime client operations."""

marshaller: "MarshallerProtocol"

def wait_next_invocation(self) -> Any: ...

def post_invocation_result(self, invoke_id: Optional[str], result_data: Any, content_type: str = "application/json") -> None: ...

def post_invocation_error(self, invoke_id: Optional[str], error_response_data: str, xray_fault: str) -> None: ...

def post_init_error(self, error_response_data: Dict[str, Any], error_type_override: Optional[str] = None) -> None: ...


class MarshallerProtocol(Protocol):
"""Protocol for request/response marshalling."""

def unmarshal_request(self, request: Any, content_type: Optional[str] = "application/json") -> Any: ...

def marshal_response(self, response: Any) -> Tuple[Any, str]: ...


class LogSinkProtocol(Protocol):
"""Protocol for logging operations."""

def log(self, msg: str, frame_type: Optional[bytes] = None) -> None: ...

def log_error(self, message_lines: List[str]) -> None: ...
Loading