Post-Deployment Steps
We’ve deployed the application in Lambda now, but still, there are a few more things to do, here we interact with production entities directly.
Configure the local system to interact with the production
To interact with the production deployment, we need to configure our local environment, like settings environment variable DJANGO_SETTINGS_MODULE (todo.settings.prod), and also other required environment variables.
Create a file with the name env_vars.sh in the project home directory with the below content (update values appropriately)
export DJANGO_SETTINGS_MODULE=todo.settings.prod export SECRET_KEY=mys3cr3tkey export SQL_DB_NAME=my_db_name export SQL_DB_USERNAME=my_db_username export SQL_DB_PASSWORD=TLQahsnbKAF9sOmI export SQL_DB_HOST=example.com export SQL_DB_PORT=3306 export USE_S3_STATIC=True export CUSTOM_AWS_ACCESS_KEY_ID=ABCDEDFGHIJKL export CUSTOM_AWS_SECRET_ACCESS_KEY=abcdefghijkl export AWS_STORAGE_BUCKET_NAME=my-storage-bucket
Then run the below command to set those environment variables, so that further commands will make use of these commands.
source env_vars.sh
Apply Migrations
Run the below command to apply migrations, these migrations will be applied in the DB server we configured in environment variables.
Deploy Static files
Run the below command to push required static (HTML templates, CSS, js, images, ) files to the AWS S3 Bucket.
Access Application
You can now access your application by using the URL shown in the deployment.
Update Deployment
We can use the below command if we wanna update our existing deployment.
zappa update <stage>
Delete Deployment
If you wanna delete your deployed application, run the below command, which will remove all the entities created for this deployment.
zappa undeploy <stage>
Conclusion: In this article, we showed you how to deploy a Django application using Zappa. Zappa makes it easy to deploy and manage your Django applications on AWS Lambda and API Gateway and provides a convenient way to keep your deployments up-to-date. Whether you’re just starting out with Django or looking to scale your existing application, deploying with Zappa is a great option.
How to Deploy Django Application in AWS Lambda?
Django is a Python web framework that makes it easy to build web applications quickly and securely. It has a large and helpful community that provides support and contributes to its development.
AWS Lambda is a serverless computing platform that runs your code in Docker containers, provides us with the best possible speed, and there is a number of third-party apps, and tools that make Lambda usage much easier, in this tutorial we gonna use one such tool.