Skip to content

Commit bf2f6fe

Browse files
committed
docs: temporarily remove larger layout sample
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
1 parent 241c587 commit bf2f6fe

File tree

1 file changed

+0
-149
lines changed

1 file changed

+0
-149
lines changed

docs/core/event_handler/api_gateway.md

Lines changed: 0 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -960,155 +960,6 @@ When necessary, you can set a prefix when including a router object. This means
960960
# many other related /users routing
961961
```
962962

963-
#### Sample larger layout
964-
965-
!!! info "We use ALB to demonstrate that the UX remains the same"
966-
967-
Below is an example project layout where we have Users routes similar to the previous example, and health check route.
968-
969-
Note that this layout optimizes for code sharing and for those familiar with Python modules. This means multiple functions will share the same `CodeUri` and package, though they are only built once.
970-
971-
!!! tip "External dependencies can be [built as a Lambda Layer](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/building-layers.html){target="_blank"} and set as `dev` dependencies for the project, though outside of scope for this documentation."
972-
973-
=== "Project layout"
974-
975-
```python hl_lines="10-13"
976-
.
977-
├── Pipfile # project dev dependencies
978-
├── Pipfile.lock
979-
├── src
980-
│ ├── __init__.py
981-
│ ├── requirements.txt # dummy for `sam build`, as external deps are Lambda Layers
982-
│ └── app
983-
│ ├── __init__.py # this file makes "app" a "Python package"
984-
│ ├── main.py # Main lambda handler (app.py, index.py, handler.py)
985-
│ └── routers # routers module
986-
│ ├── __init__.py # this file makes "routers" a "Python package"
987-
│ ├── health.py # "health" submodule, e.g. from .routers import health
988-
│ └── users.py # "users" submodule, e.g. from .routers import users
989-
├── template.yaml # SAM template.yml
990-
└── tests
991-
├── __init__.py
992-
├── unit
993-
│ ├── __init__.py
994-
│ └── test_health.py # unit tests for the health router
995-
└── functional
996-
├── __init__.py
997-
├── conftest.py # pytest fixtures for the functional tests
998-
└── test_app_main.py # functional tests for the main lambda handler
999-
```
1000-
1001-
=== "template.yml"
1002-
1003-
```yaml hl_lines="22 23"
1004-
AWSTemplateFormatVersion: '2010-09-09'
1005-
Transform: AWS::Serverless-2016-10-31
1006-
Description: Example service with multiple routes
1007-
1008-
Globals:
1009-
Function:
1010-
Timeout: 20
1011-
MemorySize: 512
1012-
Runtime: python3.9
1013-
Tracing: Active
1014-
Environment:
1015-
Variables:
1016-
LOG_LEVEL: INFO
1017-
POWERTOOLS_LOGGER_LOG_EVENT: true
1018-
POWERTOOLS_METRICS_NAMESPACE: MyServerlessApplication
1019-
POWERTOOLS_SERVICE_NAME: ServiceName
1020-
1021-
Resources:
1022-
AppFunction:
1023-
Type: AWS::Serverless::Function
1024-
Properties:
1025-
Handler: app.main.lambda_handler
1026-
CodeUri: src
1027-
Description: App function description
1028-
Events:
1029-
HealthPath:
1030-
Type: Api
1031-
Properties:
1032-
Path: /status
1033-
Method: GET
1034-
UserPath:
1035-
Type: Api
1036-
Properties:
1037-
Path: /users/{name}
1038-
Method: GET
1039-
Environment:
1040-
Variables:
1041-
PARAM1: VALUE
1042-
Tags:
1043-
LambdaPowertools: python
1044-
Outputs:
1045-
AppApigwURL:
1046-
Description: "API Gateway endpoint URL for Prod environment for App Function"
1047-
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/app"
1048-
AppFunction:
1049-
Description: "App Lambda Function ARN"
1050-
Value: !GetAtt AppFunction.Arn
1051-
```
1052-
1053-
=== "src/app/main.py"
1054-
1055-
```python hl_lines="9 14-16"
1056-
from typing import Dict
1057-
1058-
from aws_lambda_powertools import Logger, Tracer
1059-
from aws_lambda_powertools.event_handler import ApiGatewayResolver
1060-
from aws_lambda_powertools.event_handler.api_gateway import ProxyEventType
1061-
from aws_lambda_powertools.logging.correlation_paths import ALB
1062-
from aws_lambda_powertools.utilities.typing import LambdaContext
1063-
1064-
from routers import health, users
1065-
1066-
tracer = Tracer()
1067-
logger = Logger()
1068-
app = ApiGatewayResolver(proxy_type=ProxyEventType.ALBEvent)
1069-
app.include_router(health.router)
1070-
app.include_router(users.router)
1071-
1072-
1073-
@logger.inject_lambda_context(correlation_id_path=ALB)
1074-
@tracer.capture_lambda_handler
1075-
def lambda_handler(event: Dict, context: LambdaContext):
1076-
return app.resolve(event, context)
1077-
```
1078-
1079-
=== "src/app/routers/health.py"
1080-
1081-
```python hl_lines="4 6-7 10 12"
1082-
from typing import Dict
1083-
1084-
from aws_lambda_powertools import Logger
1085-
from aws_lambda_powertools.event_handler.api_gateway import Router
1086-
1087-
logger = Logger(child=True)
1088-
router = Router()
1089-
1090-
1091-
@router.get("/status")
1092-
def health() -> Dict:
1093-
logger.debug("Health check called")
1094-
return {"status": "OK"}
1095-
```
1096-
1097-
=== "tests/functional/test_app_main.py"
1098-
1099-
```python hl_lines="3"
1100-
import json
1101-
1102-
from src.app import main
1103-
1104-
1105-
def test_lambda_handler(apigw_event, lambda_context):
1106-
ret = main.lambda_handler(apigw_event, lambda_context)
1107-
expected = json.dumps({"message": "hello universe"}, separators=(",", ":"))
1108-
1109-
assert ret["statusCode"] == 200
1110-
assert ret["body"] == expected
1111-
```
1112963

1113964
#### Trade-offs
1114965

0 commit comments

Comments
 (0)