Server libraries for smithy-rs generated servers, targeting pure Python business logic.
aws-smithy-http-server-python
supports running your services on AWS Lambda.
You need to use run_lambda
method instead of run
method to start
the custom runtime
instead of the Hyper HTTP server.
In your app.py
:
```diff from pokemonserviceserversdk import App from pokemonserviceserversdk.error import ResourceNotFoundException
@app.getserverstatistics def getserverstatistics( : GetServerStatisticsInput, context: Context ) -> GetServerStatisticsOutput: callscount = context.getcallscount() logging.debug("The service handled %d requests", callscount) return GetServerStatisticsOutput(callscount=calls_count)
-app.run() +app.run_lambda() ```
aws-smithy-http-server-python
comes with a
custom runtime
so you should run your service without any provided runtimes.
You can achieve that with a Dockerfile
similar to this:
```dockerfile
FROM public.ecr.aws/lambda/python:3.8-x86_64
LAMBDA_TASK_ROOT
COPY app.py ${LAMBDATASKROOT}
pip
inside your image.COPY wheels/ ${LAMBDATASKROOT}/wheels RUN pip3 install ${LAMBDATASKROOT}/wheels/*.whl
requirements.txt
.COPY requirements.txt . RUN pip3 install -r requirements.txt --target "${LAMBDATASKROOT}"
/app.py
to refer itRUN ln -s ${LAMBDATASKROOT}/app.py /app.py
public.ecr.aws/lambda/python
images comes with Python runtime,ENTRYPOINT
and CMD
to not call that runtime andENTRYPOINT [ "/var/lang/bin/python3.8" ] CMD [ "/app.py" ] ```
See https://docs.aws.amazon.com/lambda/latest/dg/images-create.html#images-create-from-base for more details on building your custom image.
This crate is part of the AWS SDK for Rust and the smithy-rs code generator. In most cases, it should not be used directly.