- Hands-On Artificial Intelligence on Amazon Web Services
- Subhashini Tripuraneni Charles Song
- 602字
- 2021-06-24 12:48:47
Creating the base project structure
Next, let's create the hands-on project structure. Follow these steps to create the architecture and technology stack:
- In Terminal, we will create the root project directory and enter it with the following commands:
$ mkdir ObjectDetector
$ cd ObjectDetector
- We will create placeholders for the web frontend by creating a directory named Website. Within this directory, we will have two files, index.html and scripts.js, as follows:
$ mkdir Website
$ touch Website/index.html
$ touch Website/scripts.js
- We will create a Python 3 virtual environment with pipenv in the project's root directory. Our Python portion of the project needs two packages, boto3 and chalice. We can install them with the following commands:
$ pipenv --three
$ pipenv install boto3
$ pipenv install chalice
- Remember that the Python packages that were installed via pipenv are only available if we activate the virtual environment. One way to do this is with the following command:
$ pipenv shell
- Next, while still in the virtual environment, we will create the orchestration layer as an AWS Chalice project named Capabilities with the following commands:
$ chalice new-project Capabilities
This command will create a Chalice project structure within the ObjectDetector directory. The Chalice project structure should look similar to the following:
├── ObjectDetector/
├── Capabilities/
├── .chalice/
├── config.json
├── app.py
├── requirements.txt
...
In this project structure, we have the following:
- The config.json file contains configuration options for deploying our Chalice application to AWS.
- The app.py file is the main Python file where our public orchestration APIs are defined and implemented.
- The requirements.txt file specifies the Python packages that are needed by the application when it is deployed to AWS. These packages are different from the packages we installed using Pipenv. The Pipenv installed packages are the ones we need during development in the local environment; the packages in the requirements.txt file are the ones the application needs to run in the AWS cloud. For example, AWS Chalice is required during the development of the application but it is not needed once the application has been deployed to AWS.
- Now, we need to create a chalicelib Python package within the Chalice project structure in the Capabilities directory. Chalice will automatically include any of the Python files in chalicelib in the deployment package. We will use chalicelib to hold the Python classes that implement our private APIs.
To create the chalicelib package, issue the following commands:
cd Capabilities
mkdir chalicelib
touch chalicelib/__init__.py
cd ..
Note that __init__.py makes chalicelib a proper Python package.
We should have the following project directory structure:
Project Structure
------------
├── ObjectDetector/
├── Capabilities/
├── .chalice/
├── config.json
├── chalicelib/
├── __init__.py
├── app.py
├── requirements.txt
├── Website/
├── index.html
├── script.js
├── Pipfile
├── Pipfile.lock
This is the project structure for the ObjectDetector application. It contains all the layers of the AI application architecture we defined earlier. This project structure is also the base structure for all the hands-on projects in part 2 of this book.