This is part of the continuing story of Take A Number. The previous episodes are:
This episode is going to take a slight different tack: I’m interested in using new technology, if it helps me do my job. Previously, I’ve used Amazon Web Services to:
- Create an instance (EC2) and install all the services I require on it.
- Create a load balancer, so I can use Amazon for HTTPS requests.
- Create an SSL/TLS certificate for HTTPS requests.
and all of these are done using the various different interfaces.
To help me do this faster, I decided to try out Amazon’s Elastic Beanstalk service. It claims to be an (almost) language agnostic way of deploying an application without needing to know the provisioning details.
Recall that the architecture diagram looked like the deployment diagram below.
Architecture deployment diagram.
In the previous Architecture post, I mentioned the possibility of using the LAMP stack or the Microsoft stack. For simplicity, let’s take a different tack entirely: let’s use Python as our “web server” and execution environment an SQLite3 as our database.
Setting Up Elastic Beanstalk
After setting up an Amazon AWS account, I’ve clicked Create Application on the Elastic Beanstalk page.
Create New Application dialog.
I called the application TakeANumber, and I selected Python 3.6 as my environment of choice.
When I click on this green environment, I am taken to the Dashboard.
Dashboard for Take A Number.
This Dashboard shows me the most recent logs, a top-level health indication, what version of my code I am running, and the configuration that is currently being used.
Close up view of the Upload and Deploy button.
To update my code, I just need to click the Upload and Deploy button in the middle, which allows me to upload a zip file of my code.
Amazon provides a very simple example Python website (zip file!) that I’ve cut down a bit to check that I can access a local SQLite database.
def application(environ, start_response): init_database() response = welcome path = environ['PATH_INFO'] logger.info("Path is called %s", path) method = environ['REQUEST_METHOD'] logger.info("Method is called %s", method) if method == 'GET': try: if path == '/register': logger.info("Received register request!") with sqlite3.connect('take_a_number.db') as conn: cursor = conn.cursor() rows = cursor.execute('SELECT * FROM queues') for one_row in rows: response = 'Register for ' + one_row except (TypeError, ValueError): logger.warning('Error!') status = '200 OK' headers = [('Content-type', 'text/html')] start_response(status, headers) return [response] if __name__ == '__main__': httpd = make_server('', 8000, application) print("Serving on port 8000...") httpd.serve_forever()
This code (and some other Python setup code and HTML/CSS not shown) generates the web site:
Next, I’m going to revisit my analysis classes and look at turning them into the design classes I’m going to need in Python to actually implement Take A Number.