Skip to content

Commit

Permalink
Fix lambda payload format (#9)
Browse files Browse the repository at this point in the history
* build: add a Dockerfile for running the python script

* fix: fix lambda payload format in test script

* docs: update README
  • Loading branch information
suchapalaver authored Mar 1, 2024
1 parent 84b7cfd commit 3959307
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@ Check out `examples/main.rs`: running in debug mode runs a hyper server, and bui

### Testing out the Lambda runtime locally

I have also provided an example Dockerfile & python script for locally spinning up a lambda runtime:
```
There is an example Dockerfile for locally spinning up a lambda runtime:

```terminal
cargo build --release --example main
docker build . -t lambda-test
docker run -p 9000:8080 lambda-test
python test_lambda_runtime
```

In `test-lambda-runtime/` there is a python script for testing and a Dockerfile for running it.

In another shell, from the root of this repository:

```terminal
cd test-lambda-runtime
docker build . -t test_lambda_runtime
docker run --network="host" test_lambda_runtime
```
27 changes: 27 additions & 0 deletions test-lambda-runtime/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM python:3.9-slim as builder

WORKDIR /app

RUN apt-get update && \
apt-get install -y --no-install-recommends gcc

COPY requirements.txt .
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN pip install --upgrade pip && \
pip install -r requirements.txt

COPY . .

FROM python:3.9-slim

WORKDIR /app

COPY --from=builder /opt/venv /opt/venv
COPY --from=builder /app/test_lambda_runtime.py .

ENV PATH="/opt/venv/bin:$PATH"

EXPOSE 5000

CMD ["python", "test_lambda_runtime.py"]
1 change: 1 addition & 0 deletions test-lambda-runtime/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@

def mk_request(method="GET", body=None):
return {
"body": json.dumps(body) if body else "",
"headers": {
"Accept": "*/*",
"Content-Type": "application/json",
"Host": "localhost:5000",
"User-Agent": "insomnia/2022.2.1",
"User-Agent": "insomnia/2022.2.1"
},
"httpMethod": method,
"isBase64Encoded": False,
"multiValueHeaders": {
"Accept": "*/*",
"Content-Type": "application/json",
"Host": "localhost:5000",
"User-Agent": "insomnia/2022.2.1",
},
"path": "/",
"queryStringParameters": {},
"requestContext": {
"http": {
"method": method,
"path": "/",
}
},
"body": json.dumps(body) if body else "",
"isBase64Encoded": False
}


Expand Down

0 comments on commit 3959307

Please sign in to comment.