pygrestqlambda 0.0.1__tar.gz → 0.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pygrestqlambda-0.0.1 → pygrestqlambda-0.0.3}/.github/workflows/publish.yml +7 -0
- {pygrestqlambda-0.0.1 → pygrestqlambda-0.0.3}/PKG-INFO +4 -1
- {pygrestqlambda-0.0.1 → pygrestqlambda-0.0.3}/README.md +3 -0
- pygrestqlambda-0.0.3/docs/examples/direct/README.md +16 -0
- pygrestqlambda-0.0.3/docs/examples/direct/json_response.py +9 -0
- pygrestqlambda-0.0.3/docs/examples/direct/string_response.py +8 -0
- pygrestqlambda-0.0.3/docs/examples/lambda/Dockerfile +7 -0
- pygrestqlambda-0.0.3/docs/examples/lambda/README.md +35 -0
- pygrestqlambda-0.0.3/docs/examples/lambda/app.py +23 -0
- pygrestqlambda-0.0.3/docs/examples/local_lambda_gateway_compose/README.md +23 -0
- pygrestqlambda-0.0.3/docs/examples/local_lambda_gateway_compose/docker-compose.yaml +12 -0
- pygrestqlambda-0.0.3/docs/examples/local_lambda_gateway_compose/lambda/Dockerfile +9 -0
- pygrestqlambda-0.0.3/docs/examples/local_lambda_gateway_compose/lambda/app.py +22 -0
- pygrestqlambda-0.0.3/docs/examples/local_lambda_gateway_compose/lambda/requirements.txt +1 -0
- pygrestqlambda-0.0.3/docs/examples/local_lambda_gateway_compose/openapi.yaml +19 -0
- {pygrestqlambda-0.0.1 → pygrestqlambda-0.0.3}/pyproject.toml +1 -1
- pygrestqlambda-0.0.3/scripts/pre-publish.sh +7 -0
- {pygrestqlambda-0.0.1 → pygrestqlambda-0.0.3}/src/pygrestqlambda/aws/lambda_function/json_transform.py +10 -3
- pygrestqlambda-0.0.3/tests/aws/lambda_function/__init__.py +0 -0
- {pygrestqlambda-0.0.1 → pygrestqlambda-0.0.3}/tests/aws/lambda_function/test_json_transform.py +20 -1
- {pygrestqlambda-0.0.1 → pygrestqlambda-0.0.3}/.github/workflows/validate.yml +0 -0
- {pygrestqlambda-0.0.1 → pygrestqlambda-0.0.3}/.gitignore +0 -0
- {pygrestqlambda-0.0.1 → pygrestqlambda-0.0.3}/LICENSE +0 -0
- /pygrestqlambda-0.0.1/src/__init__.py → /pygrestqlambda-0.0.3/docs/examples/direct/requirements.txt +0 -0
- {pygrestqlambda-0.0.1 → pygrestqlambda-0.0.3}/scripts/validate.sh +0 -0
- {pygrestqlambda-0.0.1/src/pygrestqlambda → pygrestqlambda-0.0.3/src}/__init__.py +0 -0
- {pygrestqlambda-0.0.1/src/pygrestqlambda/aws → pygrestqlambda-0.0.3/src/pygrestqlambda}/__init__.py +0 -0
- {pygrestqlambda-0.0.1/src/pygrestqlambda/aws/lambda_function → pygrestqlambda-0.0.3/src/pygrestqlambda/aws}/__init__.py +0 -0
- {pygrestqlambda-0.0.1/src/pygrestqlambda/db → pygrestqlambda-0.0.3/src/pygrestqlambda/aws/lambda_function}/__init__.py +0 -0
- {pygrestqlambda-0.0.1 → pygrestqlambda-0.0.3}/src/pygrestqlambda/aws/lambda_function/rest_api_gateway_proxy_integration.py +0 -0
- {pygrestqlambda-0.0.1/tests → pygrestqlambda-0.0.3/src/pygrestqlambda/db}/__init__.py +0 -0
- {pygrestqlambda-0.0.1 → pygrestqlambda-0.0.3}/src/pygrestqlambda/db/record.py +0 -0
- {pygrestqlambda-0.0.1/tests/aws → pygrestqlambda-0.0.3/tests}/__init__.py +0 -0
- {pygrestqlambda-0.0.1/tests/aws/lambda_function → pygrestqlambda-0.0.3/tests/aws}/__init__.py +0 -0
- {pygrestqlambda-0.0.1 → pygrestqlambda-0.0.3}/tests/aws/lambda_function/test_rest_api_gateway_proxy_integration.py +0 -0
- {pygrestqlambda-0.0.1 → pygrestqlambda-0.0.3}/tests/test_record.py +0 -0
@@ -4,6 +4,9 @@ on:
|
|
4
4
|
push:
|
5
5
|
tags: [ '*.*.*' ]
|
6
6
|
|
7
|
+
env:
|
8
|
+
PROJECT_VERSION: ${{ github.ref_name }}
|
9
|
+
|
7
10
|
jobs:
|
8
11
|
publish:
|
9
12
|
runs-on: ubuntu-latest
|
@@ -19,6 +22,10 @@ jobs:
|
|
19
22
|
with:
|
20
23
|
python-version: '3.11'
|
21
24
|
|
25
|
+
# Run pre-publish step to update project version number to tag
|
26
|
+
- name: Pre-build
|
27
|
+
run: ./scripts/pre-publish.sh
|
28
|
+
|
22
29
|
# Re-run validation and build
|
23
30
|
- name: Validate
|
24
31
|
run: ./scripts/validate.sh
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: pygrestqlambda
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.3
|
4
4
|
Summary: PostgreSQL REST API framework for AWS Lambda functions
|
5
5
|
Project-URL: Homepage, https://github.com/mesogate/pygrestqlambda
|
6
6
|
Project-URL: Issues, https://github.com/mesogate/pygrestqlambda/issues
|
@@ -32,3 +32,6 @@ A REST API web framework for persisting records in a PostgreSQL database.
|
|
32
32
|
- Automatic setting of `created_at` and `last_updated_at` timestamps
|
33
33
|
- Automatic setting of `creator_uid` and `last_updater_uid`
|
34
34
|
- RDS with IAM credentials
|
35
|
+
|
36
|
+
## Examples
|
37
|
+
See [Examples docs directory](./docs/examples/)
|
@@ -9,3 +9,6 @@ A REST API web framework for persisting records in a PostgreSQL database.
|
|
9
9
|
- Automatic setting of `created_at` and `last_updated_at` timestamps
|
10
10
|
- Automatic setting of `creator_uid` and `last_updater_uid`
|
11
11
|
- RDS with IAM credentials
|
12
|
+
|
13
|
+
## Examples
|
14
|
+
See [Examples docs directory](./docs/examples/)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Direct python script invocation example
|
2
|
+
|
3
|
+
Navigate to the current directory from the root of this project:
|
4
|
+
```shell
|
5
|
+
cd docs/examples/direct
|
6
|
+
```
|
7
|
+
|
8
|
+
First install dependency with:
|
9
|
+
```shell
|
10
|
+
pip install pygrestqlambda
|
11
|
+
```
|
12
|
+
|
13
|
+
Then execute the scripts in this directory with, for example:
|
14
|
+
```shell
|
15
|
+
python json_response.py
|
16
|
+
```
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Lambda function docker container example
|
2
|
+
|
3
|
+
Navigate to the current directory from the root of this project:
|
4
|
+
```shell
|
5
|
+
cd docs/examples/lambda
|
6
|
+
```
|
7
|
+
|
8
|
+
From the current directory, build image with:
|
9
|
+
```shell
|
10
|
+
docker build -t pygrestqlambda/lambda .
|
11
|
+
```
|
12
|
+
|
13
|
+
The run the container with:
|
14
|
+
```shell
|
15
|
+
docker run -p 9095:8080 pygrestqlambda/lambda
|
16
|
+
```
|
17
|
+
|
18
|
+
In a separate terminal, run the following commands:
|
19
|
+
```shell
|
20
|
+
curl \
|
21
|
+
-X POST \
|
22
|
+
-d '{"hello": "from terminal"}' \
|
23
|
+
http://127.0.0.1:9095/2015-03-31/functions/function/invocations
|
24
|
+
```
|
25
|
+
|
26
|
+
The following is returned:
|
27
|
+
```json
|
28
|
+
{
|
29
|
+
"isBase64Encoded": false,
|
30
|
+
"statusCode": 200,
|
31
|
+
"headers": {"Content-Type": "application/json"},
|
32
|
+
"multiValueHeaders": null,
|
33
|
+
"body": "{\"hello\": \"from lambda handler\", \"original_input\": {\"hello\": \"from terminal\"}}"
|
34
|
+
}
|
35
|
+
```
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"""
|
2
|
+
Lambda handler
|
3
|
+
"""
|
4
|
+
|
5
|
+
import logging
|
6
|
+
from pygrestqlambda.aws.lambda_function.rest_api_gateway_proxy_integration import Response
|
7
|
+
|
8
|
+
def handler(event: dict, context: dict):
|
9
|
+
"""
|
10
|
+
Lambda handler to return supplied JSON in a format expected by AWS REST API Gateway
|
11
|
+
"""
|
12
|
+
|
13
|
+
logging.debug(context)
|
14
|
+
response = Response(
|
15
|
+
body={
|
16
|
+
'hello': 'from lambda handler',
|
17
|
+
'original_input': event
|
18
|
+
},
|
19
|
+
status_code=200,
|
20
|
+
)
|
21
|
+
payload = response.get_payload()
|
22
|
+
|
23
|
+
return payload
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# REST API Gateway Lambda function docker compose example
|
2
|
+
|
3
|
+
Navigate to the current directory from the root of this project:
|
4
|
+
```shell
|
5
|
+
cd docs/examples/local_lambda_gateway_compose
|
6
|
+
```
|
7
|
+
|
8
|
+
Start the stack with:
|
9
|
+
```shell
|
10
|
+
docker compose up --build
|
11
|
+
```
|
12
|
+
|
13
|
+
In another terminal, make a request to the example endpoint:
|
14
|
+
```shell
|
15
|
+
curl http://127.0.0.1:9096/example
|
16
|
+
```
|
17
|
+
|
18
|
+
The following response should be returned:
|
19
|
+
```json
|
20
|
+
{
|
21
|
+
"hello": "through local OpenAPI REST gateway"
|
22
|
+
}
|
23
|
+
```
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"""
|
2
|
+
Lambda handler
|
3
|
+
"""
|
4
|
+
|
5
|
+
import logging
|
6
|
+
from pygrestqlambda.aws.lambda_function.rest_api_gateway_proxy_integration import Response
|
7
|
+
|
8
|
+
def handler(event: dict, context: dict):
|
9
|
+
"""
|
10
|
+
Lambda handler to return supplied JSON in a format expected by AWS REST API Gateway
|
11
|
+
"""
|
12
|
+
|
13
|
+
logging.debug(context)
|
14
|
+
response = Response(
|
15
|
+
body={
|
16
|
+
'hello': 'through local OpenAPI REST gateway'
|
17
|
+
},
|
18
|
+
status_code=200,
|
19
|
+
)
|
20
|
+
payload = response.get_payload()
|
21
|
+
|
22
|
+
return payload
|
@@ -0,0 +1 @@
|
|
1
|
+
pygrestqlambda
|
@@ -0,0 +1,19 @@
|
|
1
|
+
openapi: 3.0.1
|
2
|
+
info:
|
3
|
+
title: Example API
|
4
|
+
version: 0.0.2
|
5
|
+
servers:
|
6
|
+
- url: http://127.0.0.1:9096
|
7
|
+
paths:
|
8
|
+
/example:
|
9
|
+
get:
|
10
|
+
responses:
|
11
|
+
'200':
|
12
|
+
description: An example response.
|
13
|
+
content:
|
14
|
+
application/json:
|
15
|
+
schema:
|
16
|
+
type: object
|
17
|
+
properties:
|
18
|
+
hello:
|
19
|
+
type: string
|
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
set -euo pipefail
|
3
|
+
|
4
|
+
# Override pyproject version if environment variable is set
|
5
|
+
PROJECT_VERSION=${PROJECT_VERSION:=0.0.0}
|
6
|
+
echo "Setting project version: ${PROJECT_VERSION}"
|
7
|
+
sed -i -e "s/version.*=.*\".*\"/version = \"${PROJECT_VERSION}\"/" pyproject.toml
|
@@ -2,9 +2,9 @@
|
|
2
2
|
JSON output transformer for non-serialisable values
|
3
3
|
"""
|
4
4
|
|
5
|
+
from datetime import date, datetime
|
6
|
+
from decimal import Decimal
|
5
7
|
from uuid import UUID
|
6
|
-
from datetime import datetime
|
7
|
-
|
8
8
|
|
9
9
|
def json_output(value: object) -> str:
|
10
10
|
"""
|
@@ -15,8 +15,15 @@ def json_output(value: object) -> str:
|
|
15
15
|
if isinstance(value, UUID):
|
16
16
|
value = str(value)
|
17
17
|
|
18
|
-
# Handle timestamps
|
18
|
+
# Handle date/timestamps
|
19
19
|
if isinstance(value, datetime):
|
20
20
|
value = value.isoformat()
|
21
21
|
|
22
|
+
if isinstance(value, date):
|
23
|
+
value = value.isoformat()
|
24
|
+
|
25
|
+
# Handle decimals
|
26
|
+
if isinstance(value, Decimal):
|
27
|
+
value = float(value)
|
28
|
+
|
22
29
|
return value
|
File without changes
|
{pygrestqlambda-0.0.1 → pygrestqlambda-0.0.3}/tests/aws/lambda_function/test_json_transform.py
RENAMED
@@ -3,7 +3,8 @@ Test JSON transformation for lambda proxy integration response
|
|
3
3
|
"""
|
4
4
|
|
5
5
|
from uuid import uuid4
|
6
|
-
from datetime import datetime
|
6
|
+
from datetime import date, datetime
|
7
|
+
from decimal import Decimal
|
7
8
|
from pygrestqlambda.aws.lambda_function.json_transform import json_output
|
8
9
|
|
9
10
|
|
@@ -25,3 +26,21 @@ def test_datetime():
|
|
25
26
|
now = datetime.now()
|
26
27
|
|
27
28
|
assert json_output(now) == now.isoformat()
|
29
|
+
|
30
|
+
|
31
|
+
def test_date():
|
32
|
+
"""
|
33
|
+
Test dates are transformed correctly
|
34
|
+
"""
|
35
|
+
|
36
|
+
today = date.today()
|
37
|
+
assert json_output(today) == today.isoformat()
|
38
|
+
|
39
|
+
|
40
|
+
def test_decimal():
|
41
|
+
"""
|
42
|
+
Test decimals are transformed correctly
|
43
|
+
"""
|
44
|
+
|
45
|
+
assert json_output(Decimal('1.0005')) == 1.0005
|
46
|
+
assert json_output(Decimal('1.00050')) == 1.0005
|
File without changes
|
File without changes
|
File without changes
|
/pygrestqlambda-0.0.1/src/__init__.py → /pygrestqlambda-0.0.3/docs/examples/direct/requirements.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
{pygrestqlambda-0.0.1/src/pygrestqlambda/aws → pygrestqlambda-0.0.3/src/pygrestqlambda}/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{pygrestqlambda-0.0.1/tests/aws/lambda_function → pygrestqlambda-0.0.3/tests/aws}/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|