Skip to main content

lambda_app_common

pip install lambda_app_common

Usage API Proxy Handler Controller

import traceback
from http import HTTPStatus

from aws_lambda_powertools.event_handler import APIGatewayRestResolver, CORSConfig, Response
from aws_lambda_powertools.event_handler.exceptions import (InternalServerError)
from aws_lambda_powertools.utilities.typing import LambdaContext

from lambda_app_common import Organization, env_vars
req_handler = Organization.ApiRequestHandler('Application', 'Service')

cors_config = CORSConfig(allow_origin=env_vars.CORS_ALLOW_ORIGIN, max_age=300)
app = APIGatewayRestResolver(cors=cors_config)

examples = Examples()

@app.get("/examples")
def get_examples():
    try:
        response = examples.find_all()
    except Exception as e:
        examples.logger.exception(e)
        print(traceback.format_exc())
        raise InternalServerError(f"get_organization {str(e)}") from e

    return Response(status_code=HTTPStatus.OK.value, content_type="application/json",
                    body=req_handler.body_data(response))



# @tracer.capture_lambda_handler()
@examples.logger.inject_lambda_context(log_event=env_vars.LOG_EVENT)
@examples.metrics.log_metrics(capture_cold_start_metric=True)
def proxy_handler(event, context: LambdaContext):
    req_handler.event = event

    req_handler.init_metrics(examples.metrics)
    # req_handler.init_tracer(admin_organization.tracer)
    req_handler.init_logger(examples.logger)

    examples.context = req_handler.get_user_context()

    response = app.resolve(event, context)
    return response
from lambda_app_common.Service import DbOrganizationService, OrganizationService

class DbOrganizationService(OrganizationService):
    def __init__(self,
                 service_name: str,
                 database: Database,
                 repository: ModelRepository,
                 event_bus: OrganizationEventBus,
                 logger: Logger,
                 tracer=None,
                 metrics=None
                 ):
        super().__init__(service_name, event_bus, logger, tracer, metrics)
        self.database = database
        self.repository = repository


class OrganizationService(PlatformService):

    def __init__(self,
                 service_name: str,
                 event_bus: OrganizationEventBus,
                 logger: Logger,
                 tracer=None,
                 metrics=None
                 ):
        super().__init__(service_name, event_bus, logger, tracer, metrics)
        self._context = None
        self._organization = None
        self._username = None
        self._user_groups = None
        self.user_applications = None
        self.user_branches = None
        self.user_zoneinfo = None
        self.user_locale = None
        self.user_env = None



class PlatformService(ABC):
    def __init__(self,
                 service_name: str,
                 event_bus: OrganizationEventBus,
                 logger: Logger,
                 tracer=None,
                 metrics=None
                 ):
        self.service_name: str = service_name
        self.current_timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        self.current_date = datetime.now().strftime('%Y-%m-%d')
        self._event_bus = event_bus
        self._logger = logger
        self._tracer = tracer
        self._metrics = metrics

Release files for lambda-app-common 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lambda-app-common 1.2.1
File Size Uploaded
lambda_app_common-1.2.1.tar.gz 10.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lambda-app-common 1.2.1
File Interpreter ABI Platform
lambda_app_common-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.5 kB

Release files / lambda_app_common-1.2.1.tar.gz

Download URL lambda_app_common-1.2.1.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a6f188ee8c4f15aa9efb4755dd0da6eda51f7dbd134545039dcc484f2a992013
BLAKE2b-256 checksum
How to use checksums
3e7764c0cab743878b5474c3e3bd7e0fef6e8194d21b61ea5e107c16e6ca5f46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / lambda_app_common-1.2.1-py3-none-any.whl

Download URL lambda_app_common-1.2.1-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36349916f65166c865f4b5f2cc330f6f6bcd5c6aeeb760883b19e375f4990be5
BLAKE2b-256 checksum
How to use checksums
6b177a51c9a9562181f0670fae3c4f5ad1561db2c056220c5a7ca4701185bcf4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.2.0

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page