Skip to content

Commit 1a63b78

Browse files
committed
Initial commit
0 parents  commit 1a63b78

8 files changed

Lines changed: 756 additions & 0 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
.idea
3+
.venv
4+
*.egg-info

LICENSE.txt

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
1. Create a virtual environment:
2+
3+
`$ python3 -m venv .venv`
4+
5+
2. Activate the created environment:
6+
7+
`$ source .venv/bin/activate`
8+
9+
3. Upgrade `pip`:
10+
11+
`$ python3 -m pip install --upgrade pip`
12+
13+
4. Install the requirements:
14+
15+
`$ pip install --upgrade -r requirements.txt`

lambda_handler/__init__.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from abc import ABC, abstractmethod
2+
from logging import getLogger, INFO, Logger
3+
from typing import Any
4+
5+
6+
class LambdaHandler(ABC):
7+
8+
def __init__(self, logger: Logger = getLogger()):
9+
10+
self.logger = logger
11+
self.logger.setLevel(INFO)
12+
13+
@abstractmethod
14+
def run(self, event: Any, context: Any) -> Any:
15+
"""Handles a Lambda event
16+
17+
:param event: Event information passed by AWS Lambda
18+
:param context: Invocation, function, and environment information
19+
:return: May return some serializable data
20+
"""
21+
22+
pass
23+
24+
def walk(self, event: Any, context: Any) -> Any:
25+
"""Handles a Lambda event, but silently
26+
27+
All exceptions are caught and logged.
28+
29+
:param event: Event information passed by AWS Lambda
30+
:param context: Invocation, function, and environment information
31+
:return: May return some serializable data
32+
"""
33+
34+
try:
35+
return self.run(event=event, context=context)
36+
except Exception as logged:
37+
self.logger.exception(logged)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-e .

setup.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
import setuptools
3+
4+
from typing import AnyStr
5+
6+
7+
GITHUB_PERSONAL_ACCESS_TOKEN = os.getenv('GITHUB_PERSONAL_ACCESS_TOKEN')
8+
9+
10+
def private_dependency(personal_access_token: AnyStr,
11+
repo_user: AnyStr, repo_name: AnyStr,
12+
package_name: AnyStr, package_version: AnyStr):
13+
"""Defines a dependency from a private Github repository
14+
15+
:param personal_access_token: Github Personal Access Token
16+
:param repo_user: Dependency repository user
17+
:param repo_name: Dependency repository name
18+
:param package_name: Dependency package name
19+
:param package_version: Dependency repository release (tag)
20+
:return: The dependency specification for the install_requires field
21+
"""
22+
23+
return f'{package_name} @ ' \
24+
f'git+https://{personal_access_token}@github.com/' \
25+
f'{repo_user}/{repo_name}.git/@{package_version}#egg={package_name}-0'
26+
27+
28+
with open('version', 'r') as version:
29+
30+
setuptools.setup(
31+
name='lambda_handler',
32+
version=version.readline(),
33+
author='Alessio Vierti',
34+
packages=setuptools.find_packages(exclude=['tests']),
35+
install_requires=[],
36+
python_requires='>=3.6'
37+
)

tests/__init__.py

Whitespace-only changes.

version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.0

0 commit comments

Comments
 (0)