pygrestqlambda 0.0.0__tar.gz → 0.0.2__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.
Files changed (36) hide show
  1. {pygrestqlambda-0.0.0 → pygrestqlambda-0.0.2}/.github/workflows/validate.yml +2 -0
  2. {pygrestqlambda-0.0.0 → pygrestqlambda-0.0.2}/PKG-INFO +4 -1
  3. {pygrestqlambda-0.0.0 → pygrestqlambda-0.0.2}/README.md +3 -0
  4. pygrestqlambda-0.0.2/docs/examples/direct/README.md +16 -0
  5. pygrestqlambda-0.0.2/docs/examples/direct/json_response.py +9 -0
  6. pygrestqlambda-0.0.2/docs/examples/direct/string_response.py +8 -0
  7. pygrestqlambda-0.0.2/docs/examples/lambda/Dockerfile +7 -0
  8. pygrestqlambda-0.0.2/docs/examples/lambda/README.md +35 -0
  9. pygrestqlambda-0.0.2/docs/examples/lambda/app.py +23 -0
  10. pygrestqlambda-0.0.2/docs/examples/local_lambda_gateway_compose/README.md +23 -0
  11. pygrestqlambda-0.0.2/docs/examples/local_lambda_gateway_compose/docker-compose.yaml +12 -0
  12. pygrestqlambda-0.0.2/docs/examples/local_lambda_gateway_compose/lambda/Dockerfile +9 -0
  13. pygrestqlambda-0.0.2/docs/examples/local_lambda_gateway_compose/lambda/app.py +22 -0
  14. pygrestqlambda-0.0.2/docs/examples/local_lambda_gateway_compose/lambda/requirements.txt +1 -0
  15. pygrestqlambda-0.0.2/docs/examples/local_lambda_gateway_compose/openapi.yaml +19 -0
  16. {pygrestqlambda-0.0.0 → pygrestqlambda-0.0.2}/pyproject.toml +1 -1
  17. {pygrestqlambda-0.0.0 → pygrestqlambda-0.0.2}/src/pygrestqlambda/aws/lambda_function/json_transform.py +4 -0
  18. pygrestqlambda-0.0.0/src/pygrestqlambda/aws/lambda_function/proxy_integration_respose.py → pygrestqlambda-0.0.2/src/pygrestqlambda/aws/lambda_function/rest_api_gateway_proxy_integration.py +5 -5
  19. pygrestqlambda-0.0.2/src/pygrestqlambda/db/__init__.py +0 -0
  20. {pygrestqlambda-0.0.0 → pygrestqlambda-0.0.2}/src/pygrestqlambda/db/record.py +11 -8
  21. pygrestqlambda-0.0.2/tests/__init__.py +0 -0
  22. pygrestqlambda-0.0.2/tests/aws/__init__.py +0 -0
  23. pygrestqlambda-0.0.2/tests/aws/lambda_function/__init__.py +0 -0
  24. pygrestqlambda-0.0.2/tests/aws/lambda_function/test_rest_api_gateway_proxy_integration.py +38 -0
  25. pygrestqlambda-0.0.2/tests/test_record.py +14 -0
  26. pygrestqlambda-0.0.0/tests/test_record.py +0 -8
  27. {pygrestqlambda-0.0.0 → pygrestqlambda-0.0.2}/.github/workflows/publish.yml +0 -0
  28. {pygrestqlambda-0.0.0 → pygrestqlambda-0.0.2}/.gitignore +0 -0
  29. {pygrestqlambda-0.0.0 → pygrestqlambda-0.0.2}/LICENSE +0 -0
  30. /pygrestqlambda-0.0.0/src/__init__.py → /pygrestqlambda-0.0.2/docs/examples/direct/requirements.txt +0 -0
  31. {pygrestqlambda-0.0.0 → pygrestqlambda-0.0.2}/scripts/validate.sh +0 -0
  32. {pygrestqlambda-0.0.0/src/pygrestqlambda → pygrestqlambda-0.0.2/src}/__init__.py +0 -0
  33. {pygrestqlambda-0.0.0/tests → pygrestqlambda-0.0.2/src/pygrestqlambda}/__init__.py +0 -0
  34. {pygrestqlambda-0.0.0/tests → pygrestqlambda-0.0.2/src/pygrestqlambda}/aws/__init__.py +0 -0
  35. {pygrestqlambda-0.0.0/tests → pygrestqlambda-0.0.2/src/pygrestqlambda}/aws/lambda_function/__init__.py +0 -0
  36. {pygrestqlambda-0.0.0 → pygrestqlambda-0.0.2}/tests/aws/lambda_function/test_json_transform.py +0 -0
@@ -8,6 +8,8 @@ on:
8
8
  jobs:
9
9
  validate:
10
10
  runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: read
11
13
  steps:
12
14
  # Checkout project code
13
15
  - uses: actions/checkout@v3
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pygrestqlambda
3
- Version: 0.0.0
3
+ Version: 0.0.2
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,9 @@
1
+ from pygrestqlambda.aws.lambda_function.rest_api_gateway_proxy_integration import Response
2
+
3
+ response = Response(
4
+ body = {
5
+ 'hello': 'world'
6
+ }
7
+ )
8
+
9
+ print(response.get_payload())
@@ -0,0 +1,8 @@
1
+ from pygrestqlambda.aws.lambda_function.rest_api_gateway_proxy_integration import Response
2
+
3
+ response = Response(
4
+ headers={'Content-Type': 'text/html'},
5
+ body = 'hello'
6
+ )
7
+
8
+ print(response.get_payload())
@@ -0,0 +1,7 @@
1
+ FROM public.ecr.aws/lambda/python:3.12
2
+
3
+ RUN pip install pygrestqlambda
4
+
5
+ COPY app.py ${LAMBDA_TASK_ROOT}
6
+
7
+ CMD [ "app.handler" ]
@@ -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,12 @@
1
+ services:
2
+ rest-api-gateway:
3
+ image: voquis/local-openapi-aws-rest-api-gateway-lambda
4
+ volumes:
5
+ - ./openapi.yaml:/openapi/openapi.yaml:ro
6
+ ports:
7
+ - 9096:8080
8
+ depends_on:
9
+ - rest-api-lambda
10
+ rest-api-lambda:
11
+ build:
12
+ context: ./lambda
@@ -0,0 +1,9 @@
1
+ FROM public.ecr.aws/lambda/python:3.12
2
+
3
+ COPY requirements.txt ${LAMBDA_TASK_ROOT}
4
+
5
+ RUN pip install -r requirements.txt
6
+
7
+ COPY . ${LAMBDA_TASK_ROOT}
8
+
9
+ CMD [ "app.handler" ]
@@ -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,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
@@ -4,7 +4,7 @@ requires = ["hatchling"]
4
4
 
5
5
  [project]
6
6
  name = "pygrestqlambda"
7
- version = "0.0.0"
7
+ version = "0.0.2"
8
8
  description = "PostgreSQL REST API framework for AWS Lambda functions"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -1,3 +1,7 @@
1
+ """
2
+ JSON output transformer for non-serialisable values
3
+ """
4
+
1
5
  from uuid import UUID
2
6
  from datetime import datetime
3
7
 
@@ -6,17 +6,17 @@ Returns payload structure expected by REST API Gateway
6
6
  https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format
7
7
  """
8
8
 
9
- import logging
10
- import json
9
+ from base64 import b64encode
11
10
  from dataclasses import dataclass
11
+ import json
12
+ import logging
12
13
  from pygrestqlambda.aws.lambda_function.json_transform import json_output
13
- from base64 import b64encode
14
14
 
15
15
 
16
16
  @dataclass
17
- class LambdaFunctionProxyIntegrationResponse:
17
+ class Response:
18
18
  """
19
- Lambda function response
19
+ Lambda function proxy response for REST API Gateway
20
20
  """
21
21
  is_base64_encoded: bool | None = False
22
22
  status_code: int | None = 401
File without changes
@@ -1,3 +1,7 @@
1
+ """
2
+ Record that represents a DB table row
3
+ """
4
+
1
5
  from abc import ABCMeta
2
6
 
3
7
 
@@ -14,53 +18,52 @@ class Record(metaclass=ABCMeta):
14
18
  Runs before a new record is created. Useful for mutating a new record
15
19
  before being committed.
16
20
  """
17
- pass
21
+
18
22
 
19
23
  def before_read(self):
20
24
  """
21
25
  Before a record is retrieved from the database. Useful for injecting
22
26
  filters or sorting.
23
27
  """
24
- pass
28
+
25
29
 
26
30
  def before_update(self):
27
31
  """
28
32
  Before a new record is created. Useful for mutating a record before it
29
33
  is committed.
30
34
  """
31
- pass
35
+
32
36
 
33
37
  def before_delete(self):
34
38
  """
35
39
  Before an existing record is deleted. Useful for e.g. updating counters
36
40
  or other aggregate fields in other tables.
37
41
  """
38
- pass
42
+
39
43
 
40
44
  def after_create(self):
41
45
  """
42
46
  Runs after a new record is created. Useful for updating e.g. counters
43
47
  tables.
44
48
  """
45
- pass
49
+
46
50
 
47
51
  def after_read(self):
48
52
  """
49
53
  After a record is retrieved from the database. Useful for transforming
50
54
  retrieved data.
51
55
  """
52
- pass
56
+
53
57
 
54
58
  def after_update(self):
55
59
  """
56
60
  Runs after a new record is updated. Useful for updating e.g. counters
57
61
  tables.
58
62
  """
59
- pass
63
+
60
64
 
61
65
  def after_delete(self):
62
66
  """
63
67
  Runs after an existing record is deleted. Useful for updating e.g.
64
68
  counters tables.
65
69
  """
66
- pass
File without changes
File without changes
@@ -0,0 +1,38 @@
1
+ """
2
+ Test REST API Gateway lambda proxy integration response
3
+ """
4
+
5
+ import base64
6
+ import json
7
+ from pygrestqlambda.aws.lambda_function.rest_api_gateway_proxy_integration import Response
8
+
9
+
10
+ def test_json_response():
11
+ """
12
+ Test JSON response is prepared correctly
13
+ """
14
+
15
+ response = Response()
16
+ response.body = {'hello': 'world'}
17
+
18
+ payload = response.get_payload()
19
+
20
+ print(payload)
21
+
22
+ assert payload['headers']['Content-Type'] == 'application/json'
23
+ assert json.loads(payload['body'])['hello'] == 'world'
24
+
25
+
26
+ def test_binary_response():
27
+ """
28
+ Test binary response is correctly prepared
29
+ """
30
+
31
+ response = Response(
32
+ body=b'hello world',
33
+ is_base64_encoded=True
34
+ )
35
+
36
+ payload = response.get_payload()
37
+
38
+ assert base64.b64decode(payload['body']) == b'hello world'
@@ -0,0 +1,14 @@
1
+ """
2
+ Test DB record
3
+ """
4
+
5
+ from pygrestqlambda.db.record import Record
6
+
7
+
8
+ def test_record():
9
+ """
10
+ Test record
11
+ """
12
+
13
+ record = Record()
14
+ assert record.after_create() is None
@@ -1,8 +0,0 @@
1
- # from pygrestqlambda.db. import Record
2
-
3
- # def test_record():
4
- # """
5
-
6
- # """
7
- # record = Record()
8
- # assert record.conn
File without changes