Spaces:
Runtime error
Runtime error
Commit
·
a724f10
1
Parent(s):
6b5fd4a
Add instructions for deployment in S3 and AWS Lambda
Browse files
README.md
CHANGED
@@ -23,4 +23,49 @@ pinned: false
|
|
23 |
## Resources
|
24 |
- [Geodesic Area calculator](https://geographiclib.sourceforge.io/cgi-bin/Planimeter?type=polygon&rhumb=geodesic&radius=6378137&flattening=1%2F298.257223563&input=40.7128%2C+-74.0060%0D%0A34.0522%2C+-118.2437%0D%0A51.5074%2C+0.1278&option=Submit)
|
25 |
- [Area calculator function in geographiclib-geodesic module's codebase](https://github.com/geographiclib/geographiclib-js/blob/main/geodesic/PolygonArea.js)
|
26 |
-
- [Country border data](https://raw.githubusercontent.com/datasets/geo-countries/master/data/countries.geojson)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
## Resources
|
24 |
- [Geodesic Area calculator](https://geographiclib.sourceforge.io/cgi-bin/Planimeter?type=polygon&rhumb=geodesic&radius=6378137&flattening=1%2F298.257223563&input=40.7128%2C+-74.0060%0D%0A34.0522%2C+-118.2437%0D%0A51.5074%2C+0.1278&option=Submit)
|
25 |
- [Area calculator function in geographiclib-geodesic module's codebase](https://github.com/geographiclib/geographiclib-js/blob/main/geodesic/PolygonArea.js)
|
26 |
+
- [Country border data](https://raw.githubusercontent.com/datasets/geo-countries/master/data/countries.geojson)
|
27 |
+
- [Link to resolve pydantic error on AWS Lambda](https://github.com/pydantic/pydantic/issues/6557#issuecomment-2402571329)
|
28 |
+
|
29 |
+
## Deployment (Without CI/CD)
|
30 |
+
|
31 |
+
- First of all calm down, take a backseat and relax
|
32 |
+
|
33 |
+
### AWS Lambda (Backend)
|
34 |
+
|
35 |
+
- AWS Lambda requires all the python packages and the function files, as it doesn't have the packages installed.
|
36 |
+
|
37 |
+
- AWS Lambda architecture should have x86 architecture.
|
38 |
+
|
39 |
+
- Make a folder lambda_build, put main.py and all the py code files keeping the structure intact (put the /backend folder i.e.)
|
40 |
+
|
41 |
+
- Install all the files in requirements.txt (as it should be in a x86 machine).
|
42 |
+
|
43 |
+
- To install the files, use `pip install "pydantic==2.0.2" --platform manylinux2014_x86_64 --target=lambda_build --implementation cp --python-version 3.10 --only-binary=:all: --upgrade` for all the libraries, handle the package name and version. (Automate it in CI/CD pipeline)
|
44 |
+
|
45 |
+
- Once the package installation is done, time for zipping.
|
46 |
+
|
47 |
+
- Go inside the lambda_build folder, select all files/folder, zip, upload it to Lambda function.
|
48 |
+
|
49 |
+
- Handle the main python file. If your main file is main.py, your handler should be main.handle (if handle = Mangum(app)), these names are flexible. If main file is lamba_function.py (with lambda_handle = Mangum(app)), then handle is lambda_function.lambda_hanle.
|
50 |
+
|
51 |
+
- Add environment files as needed on lambda. A functional url will pop up which should show {"status" : "ok"}
|
52 |
+
|
53 |
+
### AWS S3 Bucket (Frontend)
|
54 |
+
|
55 |
+
- Make a build file (npm run build)
|
56 |
+
- S3 -> my bucket -> Properties -> Static website hosting: Enable it. Set `index.html` as both source and and error doc.
|
57 |
+
- Push all the files to your S3 bucket (just the content of build, not the build folder itself)
|
58 |
+
- Set the bucket policy as
|
59 |
+
`{
|
60 |
+
"Version": "2012-10-17",
|
61 |
+
"Statement": [{
|
62 |
+
"Sid": "PublicReadGetObject",
|
63 |
+
"Effect": "Allow",
|
64 |
+
"Principal": "*",
|
65 |
+
"Action": "s3:GetObject",
|
66 |
+
"Resource": "arn:aws:s3:::my-map-frontend/*"
|
67 |
+
}]
|
68 |
+
}`
|
69 |
+
- Block all public access (Turn off 'Turn off all public access`)
|
70 |
+
- In properties, get a url to the bucket, put it inside the allowed origins of backend (Lambda)
|
71 |
+
- That's it.
|