官术网_书友最值得收藏!

Creating the base project structure

Next, let's create the hands-on project structure. Follow these steps to create the architecture and technology stack:

  1. In Terminal, we will create the root project directory and enter it with the following commands:
$ mkdir ObjectDetector
$ cd ObjectDetector
  1. 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
  1. 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
  1. 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
  1. 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.
boto3 is required when we're running our projects in the AWS cloud; however, it is already provided in the AWS Lambda runtime environment, and so we do not need to explicitly specify it in the requirements.txt file. Do remember to include any other Python packages that the applications need in that file, though.
  1. 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.

主站蜘蛛池模板: 静海县| 合江县| 龙陵县| 清水县| 馆陶县| 湟中县| 中山市| 嘉善县| 陆丰市| 香河县| 同仁县| 双江| 高阳县| 松溪县| 苏尼特左旗| 长岭县| 策勒县| 海晏县| 开鲁县| 芮城县| 鹤岗市| 新野县| 石楼县| 德兴市| 贵南县| 景洪市| 浏阳市| 榆社县| 元阳县| 兴安盟| 韶山市| 孟州市| 昭觉县| 安塞县| 肇源县| 河津市| 海淀区| 神池县| 桦南县| 沙河市| 姚安县|