Throughout all the changes in web development over the years, the server has been a constant. Regardless of the languages, tools, and frameworks used, there’s always a server running the code. And that’s something that hasn’t changed. What has changed is that cloud providers now make it easy for software engineers to focus on writing their code, without having to focus on the underlying server.
In this course, you'll build a serverless web application using Python 3.6. You'll use Lambda, API Gateway, S3, DynamoDB, and Cognito to create a multi-user to-do list application based on Vue.js.
- Outline the architecture of a serverless web application
- Set up the AWS services required for the app
- Create and deploy an API using Python 3.6
- Explain the value of creating unit tests
- Use a Cognito User Pool within your app
- DevOps Engineers
- Site Reliability Engineers
- Familiar with AWS
- Development experience
- Familiar with the CLI
Welcome back. In this lesson we'll be reviewing the Vagrant file which is used to specify the settings for the development vm as well as provision it with some software that we'll need. We'll also set up the AWS credentials file which is used to authenticate the AWS CLI. We're going to cover the Vagrant file, but we're not really going to through Vagrant in depth.
So if you're new to Vagrant, I recommend that you check out the Vagrant documentation before moving on. Alright, let's check out the Vagrant file. This is basically where all of the DevTools are going to be created. So, let's look through. We're here in visual studio code. First I wanna set this to ruby because this is a ruby syntax and the syntax highlighting will make it just a bit easier to understand.
If you're new to Vagrant, this is going to create a virtual machine and then set up port mapping. It's going to install some software so this is just going to be a bootstrap script for the virtual machine. So you can see we're binding two ports on the guest and the host. They're going to the same 8080 and 3000.
It's also syncing the folder that's this folder here. So everything in this folder will exist on the virtual machine under slash app underscore files. It's set to gui list, so no user interface. And it's set to have two gigs of memory. And then to provision it, it's going to run the shell script. What this is basically going to do.
It's going to set up python-3.6, then it'll set up some python tools such as pip virtual env. And it'll set up zip which is not a python tool but used for zipping up the files and sending them off lambda. So, here it's setting up a new virtual environment. This just allows you to have isolated applications so when you do your development, if you do them in a virtual environment, you can have all the dependencies in that environment and it's not going to mess up any other applications if they're all wrapped in a virtual environment.
So all the dependencies will localized and you don't have to worry about stomping on different versions of different binaries. So here, it's just activating that. And then it runs through pip install. So by activating it, it makes sure to install with the right version of pip, the version in our virtual env.
So we're installing moto, which is a mock version of voto, which is a library that allows you to interact with AWS with python. So it's the official python library for AWS. So we install moto, the moto server. We're also running the install for any requirements in the requirements txt. You can see there isn't one.
This is just something I add for used cases where I do actually have external dependencies. So we want to install the AWS cli. And then we make a new directory. And we link the credentials file. So you see here, app files credentials to this. There's no credentials file here, and that's because I can't commit a credentials file that has any value because there's nothing in it.
So what we're going to do is we're going to create a credentials file for this that's based off of the IAM user that we created earlier. This next one, this is just going to make sure that whenever you ssh into this Vagrant box, that it activates the correct version of virtual env. We do some appending of the python path to make sure it knows where your code is.
And then it's going to install SAM local. SAM local allows you to both run your application locally. It also allows functionality for bundling that up and deploying it using a template file so that if you're used to using CloudFormation this is going to be really familiar. If you've used the server-less framework it's also going to be familiar because this is very similar instructure.
So this has a lot of functionality. It's not something we'll be going going into in depth but it is something worth checking out. So this is going to install SAM local. The reason why it's doing a wget and then installing it manually is because there was an issue with the particular versions that I was trying to install.
NPM wasn't playing nicely. It was erroring out due to some dependencies, not due to SAM local itself. And then we come down here. Since SAM local uses docker, we need to have that installed. And so this is installing the docker container engine. So the end result of this is that this will have a virtual machine up and running, it has all of our DevTools.
However, as you noticed, it does expect that the AWS credentials file exist before it can really do anything. So before we can actually run this, we need to create that credentials file. So, let's do that. Just call it credentials. There's no extension. So what I'm going to do is I'm going to paste in the skeleton for this file.
So you can see we have a default profile here that expects an access key and a secret key as well as a region. I'm using east two. So you can change that if you've used something different. Let's grab these from our IAM. This is our access. Copy that. Paste that in. Let's jump back. This is why I wanted to leave this open.
We also downloaded the file so we could grab it from there but this makes it nice and easy. So now we save this. Okay, with this done, we're ready to actually start up the vm. In the next lesson, we'll fire up the development vm and run the test sweep to see if the code is ready to deploy. So if you're ready to keep learning, then I'll see you in the next lesson.
About the Author
Ben Lambert is a software engineer and was previously the lead author for DevOps and Microsoft Azure training content at Cloud Academy. His courses and learning paths covered Cloud Ecosystem technologies such as DC/OS, configuration management tools, and containers. As a software engineer, Ben’s experience includes building highly available web and mobile apps. When he’s not building software, he’s hiking, camping, or creating video games.