In this project, we will attach an Amazon EFS to an AWS Lambda. In the EFS, there is an XGBoost model (model.tar.gz
), which will be loaded at runtime by the AWS Lambda. Since this does not require a download from Amazon S3, it has lower latency with respect to S3.
- Run
sh build_and_push <name-of-your-liking>
in thecontainer
folder- in my case, the image name is
xgboost-lambda
. If you change it, change line 30 instack.py
- in my case, the image name is
- You can use an existing EC2 / Cloud9 / SageMaker Notebook to mount the EFS partition and upload the model. Instead, if you want the Lambda to load the model to the EFS:
- upload the model to S3 with
aws cp model.tar.gz s3://{bucket}/{prefix}/
- uncomment line 9 in the
predict.py
file adding your bucket and prefix pointing towards the.tar.gz
file containing the model - change the
bucket
line 22 instack.py
with your bucket
- upload the model to S3 with
- Run
pip install -r requirements.txt
thencdk deploy
in thestack
folder- if you don't have CDK installed, run
npm install -g aws-cdk@latest
- if you don't have CDK installed, run
- Run
test.py
from thetest
folder - Remember to change back the
predict.py
file and then redeploy your stack