How to Schedule Django Commands on AWS Elastic Beanstalk

Recently, I was looking to run a script once an hour that also required my Django app context. Though I did find a couple of online guides, they were either outdated or not comprehensive and aligned with the recent changes in AWS Elastic Beanstalk (EBS).
EBS allows us to run web apps such as Django in a seamless and managed way. That also means we shouldn’t set up any local cron jobs on our current, randomly assigned EC2 instances. Instead, we do it within our EBS environment.
In this guide, I’ll outline how to define your Django command, create an EBS config file, and deploy and test your newly created scheduled script.
Let’s assume our script is called and its purpose is to fetch new emails for a specific Gmail account on a daily basis.

#programming #django #aws #python #devops

What is GEEK

Buddha Community

How to Schedule Django Commands on AWS Elastic Beanstalk
Ahebwe  Oscar

Ahebwe Oscar


Django admin full Customization step by step

Welcome to my blog , hey everyone in this article you learn how to customize the Django app and view in the article you will know how to register  and unregister  models from the admin view how to add filtering how to add a custom input field, and a button that triggers an action on all objects and even how to change the look of your app and page using the Django suit package let’s get started.


Custom Titles of Django Admin

Exclude in Django Admin

Fields in Django Admin

#django #create super user django #customize django admin dashboard #django admin #django admin custom field display #django admin customization #django admin full customization #django admin interface #django admin register all models #django customization

How to Use AWS Elastic Beanstalk to Reduce Risk of Deployment Downtime

You can use AWS Elastic Beanstalk to create and deploy an updated or upgrated application version with blue-green deployment using cloned configs.

In this piece, I’ll be demonstrating how AWS Elastic Beanstalk can simplify deployments by doing all the hard work for you – and with no risk of downtime – by employing a Blue/Green deployment strategy.

Using AWS means combining a large number of tools to complete projects. Personally, I choose to streamline this process by using Elastic Beanstalk, as it enables me and the rest of the dev team to control the AWS resources which power the applications we support and gives us full access to the underlying resources at any time.

#cloud #aws #elastic beanstalk #aws tools #aws elastic beanstalk

Running Geo Django on ElasticBeanstalk

I want to tell you this story because I wasted about 14 hours to realize how to achieve it correctly.

NB!: Sometimes working with Elastic Beanstalk can be like this.

Long story short

To successfully run GeoDjango on Elasticbeanstalk container using Python 3.6 you need to follow these steps:

  1. Launch EC2 instance from ElasticBeanstalk image ami-0a2fbeb2675c47493. NB! Do not use EC2 instances under the control of ElasticBeanstalk for that purpose. Launch an instance from the source image used by Beanstalk;
  2. Install GDAL 2;
  3. Create a custom AMI;
  4. Run your Django app using this AMI.

The road so far

We have been using ElasticBeanstalk for 2 years to deploy our Django application in one of our projects. However, we weren’t using Geocoding features for our Django app. In one of our services, we decided to use Geo features of Django and enable PostGIS support for the project.

The problem was with missing GDAL 2 library, required for Django. There is GDAL 1 in Amazon Linux’s repositories, but it’s outdated dependency to make Django enable its GeoSpatial features.

I tried to build it from sources, installed on running instance and deployed code. Everything was fine, but I wanted to make it more reliable and be sure that it would work constantly because my changes would be deleted by autoscaling. Hence, I wanted to build a custom** AMI image **with required libraries (I needed two more, that didn’t exist in repositories).

Okay. I ran a clean configuration of the Elastic Beanstalk environment, installed everything, and created a custom AMI from EC2 instance I created using ElasticBeanstalk.

Seems pretty easy, I thought. I tried to create a new environment using this image and I found a problem with environment variables. For an unknown reason, Python container didn’t see the variables I set in the web interface.

I tried to set them using eb command and tried to set them using .ebextensions. Finally, I set them manually and had luck running the Django app, but it was unable to deploy it using eb deploy command.

In the next step I tried to use an updated image with Python 3.7 and Amazon Linux 2, but there were a lot of differences between Amazon Linux and Amazon Linux 2 that required a lot of changes in my deployment configuration.

I started thinking about what’s wrong with my configuration and why it didn’t work. I made a suggestion, that I built custom AMI wrong way and I started from the beginning.

#elastic-beanstalk #aws-elastic-beanstalk #django #python #coding #amazon #aws #ec2

Ahebwe  Oscar

Ahebwe Oscar


How model queries work in Django

How model queries work in Django

Welcome to my blog, hey everyone in this article we are going to be working with queries in Django so for any web app that you build your going to want to write a query so you can retrieve information from your database so in this article I’ll be showing you all the different ways that you can write queries and it should cover about 90% of the cases that you’ll have when you’re writing your code the other 10% depend on your specific use case you may have to get more complicated but for the most part what I cover in this article should be able to help you so let’s start with the model that I have I’ve already created it.

**Read More : **How to make Chatbot in Python.

Read More : Django Admin Full Customization step by step

let’s just get into this diagram that I made so in here:

django queries aboutDescribe each parameter in Django querset

we’re making a simple query for the myModel table so we want to pull out all the information in the database so we have this variable which is gonna hold a return value and we have our myModel models so this is simply the myModel model name so whatever you named your model just make sure you specify that and we’re gonna access the objects attribute once we get that object’s attribute we can simply use the all method and this will return all the information in the database so we’re gonna start with all and then we will go into getting single items filtering that data and go to our command prompt.

Here and we’ll actually start making our queries from here to do this let’s just go ahead and run** Python shell** and I am in my project file so make sure you’re in there when you start and what this does is it gives us an interactive shell to actually start working with our data so this is a lot like the Python shell but because we did it allows us to do things a Django way and actually query our database now open up the command prompt and let’s go ahead and start making our first queries.

#django #django model queries #django orm #django queries #django query #model django query #model query #query with django

Rory  West

Rory West


AWS Instance Scheduler Ultimate Cheat Sheet For Devs

AWS Instance Scheduler is a popular option for saving up a large portion of the cost of computing services in situations where there are predictable planned times for operating compute services. In other words, since no clients are accessing particular environments during the period, it’s normal for development environments or workloads to be shut down during non-working times.

By evaluating when the instances are more widely used, you can implement more complex schedules, or even apply an always-stopped schedule and then start up the instances when you need them.

In this article, we will cover a step-by-step guide to create an AWS schedule and apply it to several instances.

Solution Overview

This CloudFormation template creates an environment for the AWS Instance Scheduler. The solution uses the following AWS services:

#aws #aws-cost-optimization #aws-instance-scheduler #aws-savings #aws-guide