Deploy Your Django App to Serverless in  10 Minutes – Absolutely Free!

Deploy Your Django App to Serverless in 10 Minutes – Absolutely Free!

Hosting a Django Application to AWS Lambda with Zappa

Why Serverless??

  1. Less things to manage

With deploying to server, e.x., AWS ec2:?


With deploying to Serverless, e.g., aws lambda:


2. Reduced cost

  • Serverless charge you by requests, it aligns with the business models ( if you get more requests, means you get more users, only then you pay more)?


Steps

1. IAM user creation:

-Need to create a new IAM user to access the lambda function

Assign two basic permission to the IAM, IAM full access power access

2. pip3 install zappa?

-Install zappa into the project virtual environment in Django?

3.pip3 install awscli

-Install awscli into the virtual environment so that zappa can interact with lambda and API gateway?

4. aws configure

-This will ask you to enter the access key and secret key?

5. zappa init

-This will initialize the zappa configuration

6. zappa deploy dev

-Once the database is connected to django application, run this code to deploy the django application to lambda?

-What this do is 1) create lambda function to trigger the django application 2) create an API gateway to get the request

7. Django DB configuration( sqllite does not support with zappa)

https://santoshgawande.com/using-amazon-rds-with-django-a-guide-to-postgresql-integration-74f6c24f4966

https://www.youtube.com/watch?v=z_FN0Zu-Z3Q&t=55s

https://www.youtube.com/watch?v=0A-5ITILrMA&t=295s

-As zappa does not support django built in sqlite, we need to change the database to an external database, in my case, I connect it to AWS RDS.?

8. zappa update dev

-If we need to update the project, this will reflect on it

9. setup custom hostname in AWS ( https://medium.com/@amirhosseinsoltani7/connect-cloudflare-to-aws-api-gateway-c64f0713b5e9 )?

As now, we only get the API link to access our project, we can set up a custom hostname in api gateway to map with the API, here is how I did it:?

  • Download the ssl certificate info from cloudflare
  • Import ssl info to aws certificate manager
  • Create custom hostname in aws api gateway?
  • Select the imported ssl certificate
  • Create an api mapping( this will generate a mapped api domain)
  • Go to Cloudflare, add the mapped api domain as a target to CNAME of a subdomain?
  • Add this domain to allowed host in settings.py ?
  • Done?


Check the video here for more explanation:

https://www.youtube.com/watch?v=9_wWMsWlN08





Tarun Kumar

Tech Enthusiastic | React js | Next js | React Native | Redux | Backend Developer | Nodejs Developer | Node | Express | Typescript | JavaScript | MySQL | MongoDB |Aws

2 个月

thanks for contents its help me

Oskar Ablimit

Cloudflare Enterprise Account Executive | Engineering in Cloud Computing |@ex-AWS| @ex-Alicloud | @ex-Tencent Cloud

9 个月

Check the brief tutorial recording here, https://www.youtube.com/watch?v=9_wWMsWlN08

回复

要查看或添加评论,请登录

Oskar Ablimit的更多文章

社区洞察

其他会员也浏览了