Lightsail is a service that allows you get a virtual server from AWS and it is less complex than EC2.
In this article we will create a server with Lightsail, add it to Appliku as a custom server and deploy a Django app.
If you are looking for tutorial for another cloud provider checkout out one of these:
- Deploy Django on Hetzner Cloud
- Deploy Django to Digital Ocean Droplet
- Deploy Django to AWS EC2
- Deploy Django on Linode
- Deploy Django on Azure
- Deploy Django to Google Cloud Platform
Table of contents
- An application to deploy
- Appliku Account
- AWS Account
Your app should be pushed into a git repository. You can use GitHub, GitLab or any other GIT repo.
For ease of deployment we have the following recommendations:
- have the
requirements.txtfile in the root of your git repository. Don't forget to add
gunicorn(or alternative) and
psycopg2-binary==2.9.5for Postgres support
Procfilein the root of the git repository with the list of commands to run your app. Check this example
- Your app needs to respect environment variables like
DATABASE_URLfor the database credentials,
DJANGO_ALLOWED_HOSTSfor the list of allowed domains,
- Please, don't forget to have DEBUG turned off when you deploy to a publicly accessible environment.
We have a full Django with Docker and Postgres Tutorial if you want to learn more, or you can check our SpeedPy.com SaaS boilerplate
If you don't already have an Appliku Account create it by going here: https://app.appliku.com/
Click on "Add a server"
Pick a Custom Server:
Download this key, we will need it at server creation step.
If you don't already have an AWS account, go to https://portal.aws.amazon.com/billing/signup to sign up.
Because we are going to add a Lightsail as a custom server to Appliku you don't need to configure any kind of access keys in your AWS Account.
Go straight to the Lightsail dashboard: https://lightsail.aws.amazon.com/ls/webapp/home/instances
Click "Create Instance"
- OS Only
- Ubuntu 20.04 LTS
Scroll down, and click on "Change SSH Key pair"
Click "Upload New"
Click on "Upload"
Pick a public key file you have downloaded from the Appliku dashboard and click "Upload Key" button.
Pick a plan you prefer (while you can pick even the smallest instance, we recommend to pick at least $5/mo plan with 1GB RAM)
Click "Create instance"
You server is being created. Wait for "Pending" status to change to "Running"
When the status of the server changes to "Running", copy the IP address and go back to Appliku interface where we were copying the public key from.
Put the IP address into "IP" field and "ubuntu" for the user field
Click "Check credentials and add server"
Wait for server to be fully set up. Setup Status should say "Finished" and server CPU, Memory and Disk info should appear.
If setup fails you can check Setup Logs for errors.
Set up process takes a few minutes. You don't have to stare at this page the whole time, but we recommend waiting for the setup to finish before proceeding further.
Congratulations! Server is fully set up and ready to deploy our application!
Adding an application
Click on the "Applications" menu link
You will get to the Git Provider selection.
Creating application from GitHub
Select the "Setup Credentials" for GitHub.
You need to get a personal token from GitHub.
Go to this link to create a token: https://github.com/settings/tokens
Click on Generate new token -> Generate new token(Classic) Fill in the note, select expiration date, check the "repo" checkbox and "user:email"
And click "Generate token".
Copy the token from the next page.
Go back to Appliku dashboard and paste the GitHub Token, and click Test Credentials and Save
Status must change to "Active".
Click on the logo in top left corner to get back to your team and go to Applications again and create an app, select GitHub.
Fill the form with the app name, select the repository with your application, branch and select the server, click on "Create Application".
You will see your app has been created, but not yet deployed.
Creating application from GitLab
Alternatively if you use GitLab you should add credentials for GitLab and create an app from GitLab.
Go to Applications menu link, Click "Add Application" and Setup credentials for GitLab.
You need to create a Personal Access Token here: https://gitlab.com/-/profile/personal_access_tokens
Give the key a name, set or clear expiration date, select "api" checkbox and click "Create Personal Access token"
Copy the token and paste it in Appliku dashboard.
After you click "Test Credentials and Save" the Status should turn green and say "Active".
Click on the logo to go back to your team, go to Applications, Add Application and select GitLab
Give your application a name, pick repository and the branch, select the server and click "Create Application"
Setup the app
If your application needs a database, which Django apps need most of the time, you can click on the "Manage" in databases block and "Create Database"
Select a database type you need and your server to deploy the DB to, click "Create database"
Your database will start deploying, wait for the deployment status to become "deployed".
Go back to your app
You can see your database is in the list.
Environment variables and build settings
Click on the "Settings" link next to the application name.
Go to the "Environment Variables" tab
You can see that the
DATABASE_URL is already added automatically from the database you created.
If you have a
.env file you can use "Import from .env" button to paste variables.
Or click on "Add" button and add variables one by one.
Usually for Django app we need to add
Appliku provides a default host name for your application which is YOUR_APP_NAME+ '.applikuapp.com'
After you finished adding your variables click on "Save and Deploy"
You will see that the deployment started.
Go back to the application overview.
The "Deploy Now" button is grey because deployment is in progress and in the "Latest deployment" Block you can see the currently running deployment.
Click on "Deployment #1"
You can see the deployment log. Scroll down to see the most recent output.
After it finishes and reports the "exit_code: 0", which is success go back to your application overview
Click on "View Application"
It will open your application in a new window!