Skip to content

Commit 3959307

Browse files
authored
Fix lambda payload format (#9)
* build: add a Dockerfile for running the python script * fix: fix lambda payload format in test script * docs: update README
1 parent 84b7cfd commit 3959307

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,20 @@ Check out `examples/main.rs`: running in debug mode runs a hyper server, and bui
99

1010
### Testing out the Lambda runtime locally
1111

12-
I have also provided an example Dockerfile & python script for locally spinning up a lambda runtime:
13-
```
12+
There is an example Dockerfile for locally spinning up a lambda runtime:
13+
14+
```terminal
1415
cargo build --release --example main
1516
docker build . -t lambda-test
1617
docker run -p 9000:8080 lambda-test
17-
python test_lambda_runtime
18+
```
19+
20+
In `test-lambda-runtime/` there is a python script for testing and a Dockerfile for running it.
21+
22+
In another shell, from the root of this repository:
23+
24+
```terminal
25+
cd test-lambda-runtime
26+
docker build . -t test_lambda_runtime
27+
docker run --network="host" test_lambda_runtime
1828
```

test-lambda-runtime/Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM python:3.9-slim as builder
2+
3+
WORKDIR /app
4+
5+
RUN apt-get update && \
6+
apt-get install -y --no-install-recommends gcc
7+
8+
COPY requirements.txt .
9+
RUN python -m venv /opt/venv
10+
ENV PATH="/opt/venv/bin:$PATH"
11+
RUN pip install --upgrade pip && \
12+
pip install -r requirements.txt
13+
14+
COPY . .
15+
16+
FROM python:3.9-slim
17+
18+
WORKDIR /app
19+
20+
COPY --from=builder /opt/venv /opt/venv
21+
COPY --from=builder /app/test_lambda_runtime.py .
22+
23+
ENV PATH="/opt/venv/bin:$PATH"
24+
25+
EXPOSE 5000
26+
27+
CMD ["python", "test_lambda_runtime.py"]

test-lambda-runtime/requirements.txt

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

test_lambda_runtime.py renamed to test-lambda-runtime/test_lambda_runtime.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@
44

55
def mk_request(method="GET", body=None):
66
return {
7-
"body": json.dumps(body) if body else "",
87
"headers": {
98
"Accept": "*/*",
109
"Content-Type": "application/json",
1110
"Host": "localhost:5000",
12-
"User-Agent": "insomnia/2022.2.1",
11+
"User-Agent": "insomnia/2022.2.1"
1312
},
14-
"httpMethod": method,
15-
"isBase64Encoded": False,
16-
"multiValueHeaders": {
17-
"Accept": "*/*",
18-
"Content-Type": "application/json",
19-
"Host": "localhost:5000",
20-
"User-Agent": "insomnia/2022.2.1",
21-
},
22-
"path": "/",
2313
"queryStringParameters": {},
14+
"requestContext": {
15+
"http": {
16+
"method": method,
17+
"path": "/",
18+
}
19+
},
20+
"body": json.dumps(body) if body else "",
21+
"isBase64Encoded": False
2422
}
2523

2624

0 commit comments

Comments
 (0)