Adding doumentation on lambda emulation locally

This commit is contained in:
Khalim Conn-Kowlessar 2023-08-24 18:21:06 +01:00
parent c56641d8dc
commit 0883dd6c37
2 changed files with 25 additions and 5 deletions

View file

@ -120,7 +120,27 @@ Now you can run the script with
./run_lambda_local.sh
```
Then run the script with the following command:
In order to make a request to it, there is a specific format the request must be in, to
emuate lambda. If using postman, the url you want is `http://localhost:8000/2015-03-31/functions/function/invocations`
and you need to pass a body like this:
```json
{
"httpMethod": "POST",
"body": "{\"portfolio_id\": 4, \"housing_type\": \"Private\", \"goal\": \"Increase EPC\", \"goal_value\": \"C\", \"trigger_file_path\": \"2/4/portfolio_plan_properties-20230724T093542483Z.csv\"}",
"path": "/v1/plan/trigger",
"resource": "/",
"headers": {
"Accept": "*/*",
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_TOKEN_HERE",
"x-api-key": "YOUR_API_KEY_HERE"
},
"requestContext": {},
"multiValueQueryStringParameters": null
}
```
```commandline

View file

@ -4,11 +4,11 @@
IMAGE_NAME="fastapi-lambda-image"
TAG="test"
PORT="8000"
RIE_PATH="~/.aws-lambda-rie"
RIE_DIR="$HOME/.aws-lambda-rie"
DOCKER_ENTRYPOINT="$RIE_PATH/aws-lambda-rie"
DOCKER_CMD="/usr/local/bin/python -m awslambdaric backend.app.main.handler"
ENV_FILE_PATH="backend/.env"
AWS_CREDENTIALS_PATH="~/.aws/credentials"
AWS_CREDENTIALS_PATH="$HOME/.aws/credentials"
# Step 1: Download the AWS Lambda Runtime Interface Emulator if it doesn't exist
if [ ! -f "$RIE_PATH/aws-lambda-rie" ]; then
@ -27,9 +27,9 @@ echo "Starting the Docker container..."
CONTAINER_ID=$(docker run -d \
--env-file $ENV_FILE_PATH \
-v $AWS_CREDENTIALS_PATH:/root/.aws/credentials \
-v $RIE_PATH:/aws-lambda \
-v "$RIE_DIR:/aws-lambda" \
-p $PORT:8080 \
--entrypoint $DOCKER_ENTRYPOINT \
--entrypoint "/aws-lambda/aws-lambda-rie" \
$IMAGE_NAME:$TAG $DOCKER_CMD)
# Output information