Deploy Django Application on AWS EC2 with PostgreSQL and S3 Storage

Поділитися
Вставка
  • Опубліковано 23 лип 2024
  • In this video, learn how to deploy a Django application on an AWS EC2 instance with PostgreSQL and S3 storage while setting up a custom domain and SSL certificate.
    GitHub Actions CI/CD Pipeline: • Deploy project on Goog...
    Become A Backend Developer in 3 hours: • Become a Backend Devel...
    We'll start by launching an EC2 instance, configuring security groups, and installing necessary packages.
    Then, we'll create a PostgreSQL database, set up S3 storage, and configure our Django application to use them.
    Finally, we'll set up a custom domain and configure SSL encryption using Let's Encrypt, so your application is secure and accessible to your users.
    This tutorial is perfect for anyone looking to deploy a scalable Django application on AWS and ensure it's secure and reliable. So, let's get started!
    _ _ _ _ _ _ _ _ _ _ _ _ __ __ _ _ _ _
    About Channel:
    CodeWithMuh is here to help people learn about DevOps, software development, AWS, Google Cloud, and much more. I want to make it easy and quick for new developers to understand things. I also provide articles to help you learn even better with every video.
    If you like what I'm doing, you can support me by subscribing to my channel and sharing it on your social media. Let's learn and have fun together!
    _ _ _ _ _ _ _ _ _ _ _ _ __ __ _ _ _ _
    Contact:
    Email: codewithmuh@gmail.com
    LinkedIn: / muhammad-rashid-daha
    _ _ _ _ _ _ _ _ _ _ _ _ __ __ _ _ _ _
    Resources:
    Article: / deploy-django-applicat...
    GitHub Repository: github.com/codewithmuh/backen...
    Subscribe to MY Newsletter: / 7142487325682446336
    _ _ _ _ _ _ _ _ _ _ _ _ __ __ _ _ _ _
    If you would like to consult with me or hire me, please let me know.
    Hire me on Upwork: www.upwork.com/freelancers/~0...
    Place an order on Fiverr: www.fiverr.com/s/rBpEdD
    _ _ _ _ _ _ _ _ _ _ _ _ __ __ _ _ _ _
    Social Links:
    Github: github.com/codewithmuh
    LinkedIn: / muhammad-rashid-daha
    Upwork: www.upwork.com/freelancers/~0...
    X: / rashiddaha80
    Instagram: / rashiddaha1
    Medium: / codewithmuh
    Website: codewithmuh.com
    _ _ _ _ _ _ _ _ _ _ _ _ __ __ _ _ _ _
    Table of Contents:
    0:00:00 Introduction
    0:01:48 Part 01: AWS RDS PostgreSQL
    0:13:49 Part 01: AWS S3 Bucket
    0:23:44 Part 01: Deployment on AWS EC2
    0:48:27 Part 02: Domain Setup
    0:53:34 Part 02: SSL Certificate
    #aws

КОМЕНТАРІ • 148

  • @CodeWithMuh
    @CodeWithMuh  7 місяців тому

    Connect with me on LinkedIn: www.linkedin.com/in/muhammad-rashid-daha

  • @user-sw4dk1fh5g
    @user-sw4dk1fh5g Рік тому +3

    Video and tutorials to the point! It works for me. Thank you very much

  • @user-iq8rv4ro7x
    @user-iq8rv4ro7x 26 днів тому +1

    Thank you very much for this video, It has really helped me 🙏🙏🙏

  • @Yhwhaleks1602
    @Yhwhaleks1602 21 день тому +1

    amazing work! You saved my life for my project . Thank you very much !!!

  • @mazer.gabriel
    @mazer.gabriel 7 місяців тому +2

    You're awesome man! I've tried any tutorials but always the static files don't work, but you came with a simple solution, thanks man!! Definitely one more subscriber

    • @CodeWithMuh
      @CodeWithMuh  7 місяців тому

      Glad to hear 🚀

    • @mazer.gabriel
      @mazer.gabriel 7 місяців тому

      @@CodeWithMuh HEy buddy, my AWS Data Transfer is getting almost in the limit of the free tier since yesterday that I've completed the deploy. So, I think I need to use CloudFront + S3 and configure this in the nginx .conf, do you have any video about this? I think the only change aboute this video is the CloudFront

  • @The_Nairobi_Listings
    @The_Nairobi_Listings Рік тому +10

    Amazing tutorial. Even ChatGpt couldn't do what you just did there brother. Thank you. I am subscribed and a big fan

    • @CodeWithMuh
      @CodeWithMuh  Рік тому +1

      Thanks for your Love 😘

    • @anmararw
      @anmararw 25 днів тому

      Something missing. Some configuration is not explained. It's not working for me. Yes, ChatGPT helped me more.

  • @sergiybustrov8831
    @sergiybustrov8831 7 місяців тому +1

    Bro, thanks for your work! You're the best)

    • @CodeWithMuh
      @CodeWithMuh  7 місяців тому

      Glad to hear. Don't forget to connect over LinkedIn. 😉

  • @dukky4671
    @dukky4671 Рік тому +6

    Best tutorial on UA-cam, you have no idea how helpful you were. Saved my life on my school project. Thank you!

  • @kvrkvr932
    @kvrkvr932 Рік тому +1

    Awesome content bro……love from India. Keep it up bro…..we need more videos like this from you…thanks alot

  • @snxxt23_
    @snxxt23_ Рік тому +1

    helpfull!!!!! such a nice vdo ! seeking more

  • @ahmadumar9387
    @ahmadumar9387 Рік тому +1

    thanks for your explanation its awsome

  • @ghulammujtaba2261
    @ghulammujtaba2261 Рік тому +1

    Very informative video

  • @anshulsharma5890
    @anshulsharma5890 Рік тому +1

    i was also working on this type of project. It helped me, thank you

  • @TheSmashten
    @TheSmashten 7 місяців тому +1

    Absolutely wonderful tutorial, everything works perfectly. Just one small thing -- wish you could have attached the SSL medium article to the description as well.

    • @CodeWithMuh
      @CodeWithMuh  7 місяців тому

      Here you go: codewithmuh.medium.com/configure-ssl-on-aws-ec2-instance-12e49cebe451

  • @rlopxhan21
    @rlopxhan21 Рік тому +1

    quality content man

  • @concaption
    @concaption Рік тому +1

    Starting watching watching video.

  • @ingdearcilla
    @ingdearcilla 3 місяці тому +2

    good :)

  • @shabeeeb6400
    @shabeeeb6400 6 місяців тому +1

    thanks

  • @nataliogomes8303
    @nataliogomes8303 9 місяців тому +1

    YOU ARE AMAZING!!!!!!!

    • @CodeWithMuh
      @CodeWithMuh  9 місяців тому

      Happy to hear

    • @nataliogomes8303
      @nataliogomes8303 9 місяців тому

      The images uploaded to aws are not being loaded.

    • @CodeWithMuh
      @CodeWithMuh  9 місяців тому

      @@nataliogomes8303 like where

  • @superbin6021
    @superbin6021 9 місяців тому +1

    36:43 static() function has if condition for debug mode settings.DEBUG. So you don't need to create a new if condition again

  • @paulkaranja7670
    @paulkaranja7670 Рік тому +1

    This is a nice tutorial, Thanks Muh!! +1 Subsciption. Code on Bro

  • @lestatblaq84
    @lestatblaq84 Рік тому +4

    You skipped a very important part towards the end of provisioning a Postgres DB, configuring the inbound security rules. Very important or the database won't be accessible from your app. Informative tutorial overall, thank you

    • @CodeWithMuh
      @CodeWithMuh  Рік тому +3

      Right.
      In this video i did migrations from localhost to RDS. So we can handle from there as well.
      But as you said from EC2, you are right.
      You can add RDS security group in ec2 security group .

    • @dmytromalevskyi400
      @dmytromalevskyi400 Рік тому +2

      exactly

    • @fuattatar
      @fuattatar Місяць тому +1

      @@CodeWithMuh yes adding postgres security group to ec2 worked. Thanks

  • @johncampilla4146
    @johncampilla4146 6 місяців тому +1

    Thank you for your tutorial regarding deployment of django application on AWS it was an amazing learning experience I've waited this for so long, a wonderful tutorial indeed...i closely watch and followed every steps of your tutorial from RDS, S3, IAM running it from my localhost attached to a aws RDS postgreSQL and S3 everything is working fine.. until i started to follow the tutorial for the EC2 from the updating of EC2 environment , to setting up of virtual environment, cloning my git to EC2 set up... started the 'makemigrations' from the terming of EC2..no errors have been displayed however the program hangs and automatically disconnects from EC2 , also done the 'migrate' same no errors but program hangs.. mr. Muh should you have in mind as to what / where I am wrong. please advise. Thank you.

    • @CodeWithMuh
      @CodeWithMuh  6 місяців тому

      There are chances you have a made mistake somewhere. Reach out to me at LinkedIn with A text message. I will try to help you out

    • @johncampilla4146
      @johncampilla4146 6 місяців тому

      @@CodeWithMuh thank u so much and sorry for my late reply we have different time zone u know.. will get in touch w u later sir Muh….

  • @John4STEM
    @John4STEM Рік тому +1

    Thanks for your great video Muhammed. We are looking at deploying our Django (backend) and VueJS (frontend) application. Please let us know if you can take us through this process (online) and how much you will charge for this. Thanks and hope to hear from you.

    • @CodeWithMuh
      @CodeWithMuh  Рік тому

      Please email me at codewithmuh@gmail.com

    • @John4STEM
      @John4STEM Рік тому

      @@CodeWithMuh Great, I have emailed you just now. Thanks

    • @CodeWithMuh
      @CodeWithMuh  Рік тому

      Just replied you

  • @user-rs9uf1ii1o
    @user-rs9uf1ii1o Рік тому +3

    If I am using S3 for my static files, should I still follow the whitenoise section of this tutorial?

  • @javiermadriz7834
    @javiermadriz7834 9 місяців тому +1

    I have seen that some people put Ip address or domain in nginx file, this you simplified when you used cloudflare?

    • @CodeWithMuh
      @CodeWithMuh  9 місяців тому

      No, its not mandatory with cloudflare use

  • @johncampilla4146
    @johncampilla4146 Місяць тому +1

    Hi Mr. Muh, Can I just install a PostgreSQL package inside the ssh environment on an AWS EC2 instance without creating or configuring the AWS RDS instance? Thanks for your prompt response.

    • @CodeWithMuh
      @CodeWithMuh  Місяць тому

      Yes you can

    • @johncampilla4146
      @johncampilla4146 Місяць тому +1

      @@CodeWithMuh thank you for your reply. What will be the 'endpoint' if ever ?

    • @CodeWithMuh
      @CodeWithMuh  Місяць тому

      It will be ip

  • @abhisheksharma10600
    @abhisheksharma10600 Місяць тому +1

    how can i setup environement variables in my ec2 instance as env variables are not in the github repo ?

    • @CodeWithMuh
      @CodeWithMuh  Місяць тому

      You have to create .env on ec2 at your project folder

  • @muhammedmuneeb7000
    @muhammedmuneeb7000 10 місяців тому +2

    If anyone have "refused to connect" issue, configure gunicorn in the default file.

  • @Sandeep-tn8mz
    @Sandeep-tn8mz 2 місяці тому +1

    Hey , i had one small doubt ... The Ipv4 will change whenever we restart the ec2 instance ...right?

    • @CodeWithMuh
      @CodeWithMuh  2 місяці тому

      Yes, you have to create elastic ip, then attach to ec2. Then it will not get updated

  • @louiedominicfrancia1746
    @louiedominicfrancia1746 2 місяці тому +1

    Can you explain to me on why I didn't get the ONLINESHOP Section when I first Logged-in at the Django administration? It only contains the AUTHENTICATION AND AUTHORIZATION Section :< Please help

    • @CodeWithMuh
      @CodeWithMuh  2 місяці тому

      we had a chat on linkedin.

    • @louiedominicfrancia1746
      @louiedominicfrancia1746 2 місяці тому +1

      @@CodeWithMuh Yup ! Thank you very VERY VERY MUCH! I really appreciate it !

  • @saidmurodsabirov612
    @saidmurodsabirov612 7 місяців тому +1

    Legend!

    • @CodeWithMuh
      @CodeWithMuh  7 місяців тому

      Glad to hear. My videos are helping others.

  • @johng2587
    @johng2587 4 місяці тому +2

    Thank you! Please explain to your viewers the reason "why?" you are doing things. Why use white noise? What problem does that solve? Why are any of the settings.py lines added? What do they do? What happens if I do not add the lines?

    • @CodeWithMuh
      @CodeWithMuh  4 місяці тому

      You are right. I will improve the content by giving some more time. Because to create more in detailed content, it takes time. As i am working as a freelancer, it's become difficult to give time. But now i am managing to give a quality video every week.
      I appreciated your feedback, it will help to add some details in my content

    • @CodeWithMuh
      @CodeWithMuh  4 місяці тому

      I would like to connect with you on LinkedIn.

  • @vitorangheben80
    @vitorangheben80 9 місяців тому +1

    Muh, I've done all the steps in the EC2 part, but in the end my project is not being display when I run the 'ls' command and I have no idea why, everything else is working correctly
    Any help here I would appreciate very much, and tks for this video

    • @CodeWithMuh
      @CodeWithMuh  9 місяців тому

      There will be a mistake somewhere in your set-up. Send me a message on email

  • @vitorangheben80
    @vitorangheben80 Рік тому +1

    Muh, on minute 10:15 you establish an inbound rule, I try to the same thing but I'm receiving this error:
    "You cannot specify an IPv4 CIDR for an existing referenced group ID rule."
    How can I fix that??
    Very good video, tks!

    • @CodeWithMuh
      @CodeWithMuh  Рік тому

      Can you share screenshot via drive url. Show me how you filled.

    • @CodeWithMuh
      @CodeWithMuh  Рік тому

      There will be mistake. Show me your screenshot, so i can review

    • @CodeWithMuh
      @CodeWithMuh  Рік тому

      Or post here. fb://group/890525732087988?ref=share&mibextid=NSMWBT

    • @vitorangheben80
      @vitorangheben80 Рік тому

      @@CodeWithMuh take a look in that word file in my drive
      drive.google.com/drive/folders/1kqmLUQZ_sLf51jIqHeLuHgEHV9C0wdNj?usp=sharing
      Tks!

    • @vitorangheben80
      @vitorangheben80 Рік тому

      @@CodeWithMuh I don't think it's a mistake, I follow your steps, looks like to be a problem in security AWS Service Muh, if you can please, check the file that I've shared with you on my drive

  • @ragacola
    @ragacola 4 місяці тому

    can you explain the purpose of S3 in this setup? is it just for backup and redundancy?

    • @CodeWithMuh
      @CodeWithMuh  4 місяці тому +1

      S3 is used to store files. Suppose a blog model has a cover image, when we create a new blog and upload an image, it will be stored over the s3 bucket.

    • @ragacola
      @ragacola 4 місяці тому

      @@CodeWithMuh oh ok. So the data for our database is stored in S3, and not in RDS? I thought RDS is where files were stored because thats where postgres is installed.

    • @CodeWithMuh
      @CodeWithMuh  4 місяці тому +1

      Rds is being used for tables. S3 is being used for binary/images/pdf files. Both have different use

  • @RishiKumar-ec4of
    @RishiKumar-ec4of Рік тому

    Sir I have a problem in nginx 404 page not found my django default admin can you please explain

    • @CodeWithMuh
      @CodeWithMuh  Рік тому +1

      Nginx is not configured. Please post your nginx screenshot in our Facebook group community for help. Group name is given in video description

  • @keteretsu9252
    @keteretsu9252 8 місяців тому +2

    My django Restframwork Project is working fine on the public IP address but not on the domain name...
    if I try to access using http it says server is down error code 521
    !HELP

    • @CodeWithMuh
      @CodeWithMuh  8 місяців тому

      Make sure your domain is properly pointed to your domain

    • @keteretsu9252
      @keteretsu9252 8 місяців тому

      set the ssl setting to flexible instead of full and it worked..
      also used certbot made it more simpler

  • @sulaimanibrahim7796
    @sulaimanibrahim7796 Рік тому +2

    I am using windows. after pasting the gunicorn code how do I save and exit? Which commands should I use?

    • @CodeWithMuh
      @CodeWithMuh  Рік тому +1

      Crt + C or CRT+ x.

    • @sulaimanibrahim7796
      @sulaimanibrahim7796 Рік тому +1

      @@CodeWithMuh thank you

    • @vitorangheben80
      @vitorangheben80 9 місяців тому

      @@sulaimanibrahim7796 does it work for you?
      When I try to run the command 'sudo systemctl start gunicorn.socket' I'm receiving an error, so I think it's not saving

    • @sulaimanibrahim7796
      @sulaimanibrahim7796 9 місяців тому +1

      @vitorangheben80 yeah it worked for me. When you click ctrl x you'll see a prompt about saving you press y then enter

  • @sulaimanibrahim7796
    @sulaimanibrahim7796 10 місяців тому

    Hey I have an error when I try it. My IP address works well on the browser but when I connect the domain name to the IP address using Cloudflare I get the welcome to nginx page. When I input the domain name it shows the nginx welcome page. Can you please help?

    • @CodeWithMuh
      @CodeWithMuh  10 місяців тому

      Share your Nginx file code

    • @sulaimanibrahim7796
      @sulaimanibrahim7796 10 місяців тому

      I deleted my other nginx configuration and I used yours. My IP address is working but when I type my domain name it shows "Bad request 400" @@CodeWithMuh

  • @sergiodanielsigalahernande5033

    bro makemigrations not working for me
    RuntimeWarning: Got an error checking a consistent migration history performed for database connection 'default': connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: role "ubuntu" does not exist
    warnings.warn(
    anyone know to fix?

    • @CodeWithMuh
      @CodeWithMuh  Рік тому +1

      Your configurations are worng. Did you added role Ubuntu?

    • @sergiodanielsigalahernande5033
      @sergiodanielsigalahernande5033 Рік тому

      @@CodeWithMuh no friend in which part of the tutorial comes how to do it

    • @CodeWithMuh
      @CodeWithMuh  Рік тому +1

      Make sure your socket configuration is correct

    • @syedfarhan4688
      @syedfarhan4688 9 місяців тому

      did it resolve if yes please help me i'm stuck into it

  • @finesttv_rsa7117
    @finesttv_rsa7117 Місяць тому

    How to fix system has not yet been booted with systemd as init system??? Failed to connect to bus: host us down. Please help me

    • @CodeWithMuh
      @CodeWithMuh  Місяць тому +1

      I didn’t get your issue. Send me message on linkedin

    • @finesttv_rsa7117
      @finesttv_rsa7117 Місяць тому

      @@CodeWithMuh I did send

  • @abbasalitmk
    @abbasalitmk Рік тому

    how force redirect to https. currently need to enter https manually

  • @Sports-Made
    @Sports-Made Рік тому +1

    Did all the steps, but when I try to access the page all I get is “this site can’t be reached” (my ec2 ip) refused to connect….. any help?

    • @CodeWithMuh
      @CodeWithMuh  Рік тому +2

      You will have issues in gunicorn, nginx, or security groups. Make sure all these things are correctly configured.

    • @Sports-Made
      @Sports-Made Рік тому +1

      @@CodeWithMuh the issue was with the security groups…. Thanks for the great tutorial…

    • @CodeWithMuh
      @CodeWithMuh  Рік тому

      @@Sports-Made Glad to hear

    • @muhammedmuneeb7000
      @muhammedmuneeb7000 10 місяців тому

      If still not working, configure gunicorn in the default file and try again.

    • @raihan658
      @raihan658 7 місяців тому

      i'm also facing the same issue that you have . i have followed all thing correctly also didnt get any error , could you please share what did you change in the security groups , or please provide you instagram id or any other contact details plsease its urgent

  • @Bryan-mw1wj
    @Bryan-mw1wj 10 місяців тому

    Hello good tutorial, I am running into 502 Bad Gateway Error nginx/1.18.0 (Ubuntu) after configuring the EC2 instance and RDS correctly. Any idea what is wrong?

    • @CodeWithMuh
      @CodeWithMuh  10 місяців тому

      Check your ngnix file. Also check logs error. Or check Gunicorn errors

    • @muhammedmuneeb7000
      @muhammedmuneeb7000 10 місяців тому

      Its may be missing of credentials.
      check the status of gunicorn

    • @AmFidelMunywoki
      @AmFidelMunywoki 9 місяців тому

      Hello, Bryan how did you solve , running into the same error

    • @Bryan-mw1wj
      @Bryan-mw1wj 9 місяців тому

      Hey, I hate to say it but I used another tutorial to finish

    • @CodeWithMuh
      @CodeWithMuh  9 місяців тому

      There will be something wrong in nginx. Share your nginx.

  • @javiermadriz7834
    @javiermadriz7834 9 місяців тому +1

    Why did not use Route 53 to get a domain?

    • @CodeWithMuh
      @CodeWithMuh  7 місяців тому

      If you want to use. You can

  • @programmer9809
    @programmer9809 2 місяці тому

    3:25

  • @raju_bugude
    @raju_bugude Рік тому +1

    this deployment is eligible for a free tier account in aws?

    • @CodeWithMuh
      @CodeWithMuh  Рік тому

      Yes, eligible

    • @aleda97
      @aleda97 4 місяці тому

      Is it still? I'm getting charge for usage of IPv4 address

    • @fuattatar
      @fuattatar Місяць тому +1

      @@aleda97 same for me :(

  • @pinakipattanaik6023
    @pinakipattanaik6023 Рік тому

    Hi, thanks for ur great videos, I got 502 nginx errors after successfully completion of each step in ec2

  • @vijaykumarakunoori8144
    @vijaykumarakunoori8144 Рік тому +1

    Hi , Thanks for your content
    I went through your video and deployed my djnago application on ec2
    after completion, I'm getting like on browser
    This site can’t be reached3.93.144.168
    refused to connect.
    Try:
    Checking the connection
    Checking the proxy and the firewall
    ERR_CONNECTION_REFUSED
    Can you please help here, I'm stuck here ,How to fix it

    • @raihan658
      @raihan658 7 місяців тому

      facing the same issue , do you have any solution

  • @Coden69
    @Coden69 Рік тому +1

  • @gjtechtalk
    @gjtechtalk Рік тому +1

    Very informative video