Sorry Docker starter question here.
I’m currently trying to build an app with Python using FastApi and dockerize it. When it’s dockerized I will connect it to an AWS Lambda. The problem is, how can I test my Lambda before deploying it to ECR?
I already tried to use the local Lambda invoke with: localhost:9000/2015-03-31/functions/function/invocations and create a post request reading a file:
{
"resource": "/",
"path": "/upload/",
"httpMethod": "POST",
"requestContext": {},
"multiValueQueryStringParameters": null,
"headers": {
"Accept": "application/json",
"Content-Type": "application/json" },
"body": { "filename": "image.jpg" },
"files": { "upload": "image.jpg" }
}
I don’t get it to work…
Code:
@app.post("/upload/")
async def upload_image(request: Request):
print(request)
print(await request.json())
print(await request.body())
return {"received_request_body": request.json()}
handler = Mangum(app)
2
Answers
Does your container image include the runtime interface emulator (RIE)? Did you build and run the container image? Take a read through the following reference:
You might also check out AWS SAM CLI, which offers a nice workflow for local build and test of Lambda functions.
I am not sure about your complete infra.But based on the above given limited information I am trying to answer.
You can test lambda independently with test events.You can do this from either AWS console or from cli (aws lambda invoke).
Reference:
https://docs.aws.amazon.com/lambda/latest/dg/testing-functions.html
But if you want to test it with api then use api gateway along with your lambda which will expose it as an endpoint.Then you can test your lambda which ever way you are comfortable(like curl command/postman etc..)
Reference
Api Gateway with lambda
Navigation for test event from Lambda console
Test event for Lambda screenshot