Clement Vachet commited on
Commit
c8a57bb
·
1 Parent(s): b58c566

docs: add documentation for AWS deployment

Browse files
Files changed (1) hide show
  1. README.md +82 -13
README.md CHANGED
@@ -14,34 +14,103 @@ short_description: Object detection Lambda
14
 
15
  <b>Aim: AI-driven object detection task</b>
16
  - Front-end: user interface via Gradio library
17
- - Back-end: use of AWS Lambda function to run ML models
18
 
19
  ## Local development
20
 
21
- ### User interface
22
- Use of Gradio library for web interface
23
-
24
- Command line:
25
- > python3 app.py
26
-
27
- <b>Note:</b> The Gradio app should now be accessible at http://localhost:7860
28
-
29
 
30
- ### Building the docker image:
31
 
32
  bash
33
  > docker build -t object-detection-lambda .
34
 
35
- ### Running the docker container locally:
36
 
37
  bash
38
 
39
  > docker run --name object-detection-lambda-cont -p 8080:8080 object-detection-lambda
40
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
- ### Testing locally:
43
 
44
  Example of a prediction request
45
 
 
 
 
 
 
 
 
46
  python
47
- > python3 inference_api.py --api http://localhost:8080/2015-03-31/functions/function/invocations --file ./tests/data/boats.jpg
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  <b>Aim: AI-driven object detection task</b>
16
  - Front-end: user interface via Gradio library
17
+ - Back-end: use of AWS Lambda function to run deployed ML models
18
 
19
  ## Local development
20
 
 
 
 
 
 
 
 
 
21
 
22
+ ### 1. Building the docker image
23
 
24
  bash
25
  > docker build -t object-detection-lambda .
26
 
27
+ ### 2. Running the docker container locally
28
 
29
  bash
30
 
31
  > docker run --name object-detection-lambda-cont -p 8080:8080 object-detection-lambda
32
 
33
+ ### 3. Execution via user interface
34
+ Use of Gradio library for web interface
35
+
36
+ <b>Note:</b> The environment variable ```AWS_API``` should point to the local container
37
+ > export AWS_API=http://localhost:8080
38
+
39
+ Command line for execution:
40
+ > python3 app.py
41
+
42
+ The Gradio web application should now be accessible at http://localhost:7860
43
+
44
 
45
+ ### 4. Execution via command line:
46
 
47
  Example of a prediction request
48
 
49
+ bash
50
+ > encoded_image=$(base64 -i ./tests/data/boats.jpg)
51
+
52
+ > curl -X POST "http://localhost:8080/2015-03-31/functions/function/invocations" \
53
+ > -H "Content-Type: application/json" \
54
+ > -d '{"body": "'"$encoded_image"'", "isBase64Encoded": true, "model":"yolos-small"}'
55
+
56
  python
57
+ > python3 inference_api.py \
58
+ > --api http://localhost:8080/2015-03-31/functions/function/invocations \
59
+ > --file ./tests/data/boats.jpg \
60
+ > --model yolos-small
61
+
62
+
63
+ ## Deployment to AWS
64
+
65
+ ### Pushing the docker container to AWS ECR
66
+
67
+ Steps:
68
+ - Create new ECR Repository via aws console
69
+
70
+ Example: ```object-detection-lambda```
71
+
72
+
73
+ - Optional for aws cli configuration (to run above commands):
74
+ > aws configure
75
+
76
+ - Authenticate Docker client to the Amazon ECR registry
77
+ > aws ecr get-login-password --region <aws_region> | docker login --username AWS --password-stdin <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com
78
+
79
+ - Tag local docker image with the Amazon ECR registry and repository
80
+ > docker tag object-detection-lambda:latest <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/object-detection-lambda:latest
81
+
82
+ - Push docker image to ECR
83
+ > docker push <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/object-detection-lambda:latest
84
+
85
+ [Link to AWS Documention](https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html)
86
+
87
+ ### Creating and testing a Lambda function
88
+
89
+ <b>Steps</b>:
90
+ - Create function from container image
91
+
92
+ Example name: ```object-detection```
93
+
94
+ - Notes: the API endpoint will use the ```lambda_function.py``` file and ```lambda_hander``` function
95
+ - Test the lambda via the AWS console
96
+
97
+
98
+ Advanced notes:
99
+ - Steps to update the Lambda function with latest container via aws cli:
100
+ > aws lambda update-function-code --function-name object-detection --image-uri <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/object-detection-lambda:latest
101
+
102
+
103
+ ### Creating a REST API via API Gateway
104
+
105
+
106
+ <b>Steps</b>:
107
+ - Create a new ```Rest API``` (e.g. ```object-detection-api```)
108
+ - Add a new resource to the API (e.g. ```/detect```)
109
+ - Add a ```POST``` method to the resource
110
+ - Integrate the Lambda function to the API
111
+ - Notes: currently using proxy integration option unchecked
112
+ - Deploy API with a specific stage (e.g. ```dev``` stage)
113
+
114
+ Example AWS API Endpoint:
115
+ ```https://<api_id>.execute-api.<aws_region>.amazonaws.com/dev/detect```
116
+