Clement Vachet commited on
Commit
b353ed7
·
1 Parent(s): 8631332

Add documentation for AWS deployment

Browse files
Files changed (1) hide show
  1. README.md +59 -4
README.md CHANGED
@@ -2,6 +2,8 @@
2
 
3
  Workflow: use of AWS lambda function for deployment
4
 
 
 
5
  ### Training the model:
6
 
7
  bash
@@ -30,9 +32,62 @@ python
30
  > python3 inference_api.py --url http://localhost:8080/2015-03-31/functions/function/invocations -d '{"features": [[6.5, 3.0, 5.8, 2.2], [6.1, 2.8, 4.7, 1.2]]}'
31
 
32
 
33
- ### Deployment to AWS
 
 
34
 
35
  Steps:
36
- - Pushing the docker container to AWS ECR
37
- - Creating and testing a Lambda function
38
- - Creating an API via API Gateway
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  Workflow: use of AWS lambda function for deployment
4
 
5
+ ## Local development
6
+
7
  ### Training the model:
8
 
9
  bash
 
32
  > python3 inference_api.py --url http://localhost:8080/2015-03-31/functions/function/invocations -d '{"features": [[6.5, 3.0, 5.8, 2.2], [6.1, 2.8, 4.7, 1.2]]}'
33
 
34
 
35
+ ## Deployment to AWS
36
+
37
+ ### Pushing the docker container to AWS ECR
38
 
39
  Steps:
40
+ - Create new ECR Repository via aws console
41
+
42
+ Example: ```iris-classification-lambda```
43
+
44
+
45
+ - Optional for aws cli configuration (to run above commands):
46
+ > aws configure
47
+
48
+ - Authenticate Docker client to the Amazon ECR registry
49
+ > aws ecr get-login-password --region <aws_region> | docker login --username AWS --password-stdin <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com
50
+
51
+ - Tag local docker image with the Amazon ECR registry and repository
52
+ > docker tag iris-classification-lambda:latest <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/iris-classification-lambda:latest
53
+
54
+ - Push docker image to ECR
55
+ > docker push <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/iris-classification-lambda:latest
56
+
57
+ [Link to AWS Documention](https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html)
58
+
59
+ ### Creating and testing a Lambda function
60
+
61
+ <b>Steps</b>:
62
+ - Create function from container image
63
+
64
+ Example name: ```iris-classification```
65
+
66
+ - Notes: the API endpoint will use the ```lambda_function.py``` file and ```lambda_hander``` function
67
+ - Test the lambda via the AWS console
68
+
69
+ Example JSON object:
70
+ ```
71
+ {
72
+ "features": [[6.5, 3.0, 5.8, 2.2], [6.1, 2.8, 4.7, 1.2]]
73
+ }
74
+ ```
75
+
76
+ Advanced notes:
77
+ - Steps to update the Lambda function with latest container via aws cli:
78
+ > aws lambda update-function-code --function-name iris-classification --image-uri <aws_account_id>.dkr.ecr.<aws_region>.amazonaws.com/iris-classification-lambda:latest
79
+
80
+
81
+ ### Creating an API via API Gateway
82
+
83
+
84
+ <b>Steps</b>:
85
+ - Create a new ```Rest API``` (e.g. ```iris-classification-api```)
86
+ - Add a new resource to the API (e.g. ```/classify```)
87
+ - Add a ```POST``` method to the resource
88
+ - Integrate the Lambda function to the API
89
+ - Notes: using proxy integration option unchecked
90
+ - Deploy API with a specific stage (e.g. ```test``` stage)
91
+
92
+ Example API Endpoint URL:
93
+ https://<api_id>.execute-api.<aws_region>.amazonaws.com/test/classify