Turn your ML model into a web service in under 10 minutes with AWS CodeStar

I trained the model on German text and stored it as a Python Pickle file.By the end of this post, we will have a working web service that takes in one variable through a GET request, runs the model via Python code and returns the resulting prediction as JSON.Step 1: Creating your CodeStar projectOver 30 templates make it easy to set up your web service or appSince our goal is to establish a web service, we can choose the first Python template..CodeStar will then create the repository for you with all necessary files in it, but more on those later.To work its magic, CodeStar needs permission to manage all the different tools in our pipeline on your behalf.Our AWS CodePipelineStep 2: Connect to your source repositoryOne of the great things about CodeStar is that the code is all managed via Git and every update you push into it, will update the Lambda function and automatically be deployed..Since AWS automatically creates the repository for you, all that needs to be done to start coding is a git clone your_repository_url.AWS CodeStar creates all the necessary files for youStep 3: Create GET parameter in AWS APIGatewayTo make changes in the API parameters, we need to open our project in AWS APIGateway..The created repository contains the following items by default:index.py: This file contains the code for your Lambda function.README.md: The readme file contains basic information about the next steps to take and links to the official documentation.template.yml: The structure of your ‘serverless’ AWS architecture.buildspec.yml: This file contains additional commands that are executed during the build process..A standard command pre-build is the execution of a unit test.tests/: Contains the file test_handler.py with the unit test mentioned above.First, we have to make our model file accessible to the function..Once uploaded, Lambda can access the file the usual way, using open.Finally, we can write our Python code into index.py, which will become our Lambda function..For that reason, we update everything accordingly:All we have to do now is to push the model file, and code to the project repository, using the usual commands: git add ., git commit, and git push.. More details

Leave a Reply