Article

From Zero to Cloud in Minutes: Let’s Take a Vote

Getting serverless apps to the cloud can be easy. A common question asked though is, “Where do I start?” However, it can be easier than you may realize to get from zero to the cloud.

Let’s start with a common problem: We would like to poll a room an icebreaker question such as, “Would you rather fight 100 duck-sized horses or 1 horse-sized duck?” But perhaps you would rather not share it globally or deal with free app advertisements (I’m looking at you, SurveyMonkey.)

So, how can we do this quickly, easily, and cost-effectively using the cloud?

Goals

  • Quickly set up and test a poll
  • Launch the poll in Azure

Prerequisites

  • A handful of resources of your choice like Git, Python, and Azure command line tools
  • An Azure account (You can sign up for free here.)

Let’s Drop in Some Code and Try It Locally

Rather than start with a blank app, let’s get started by using an example from the Azure Customer Advisory Team. Launch a command prompt and go to a folder we can use for this project (I generally make a Workspaces folder for my Git repositories.).

Next, switch to an Administrator Powershell Window (or use a sudo command if you’re on a Mac in a terminal window).

pip install -r requirements.txt

Our next step is to modify the options since “cats” versus “dogs” is pretty boring (Besides, there’s a clear winner on that topic, but I digress.).

Launch your favorite editor and change the options in config_file.cfg

VOTE1VALUE = ‘100 Duck Sized Horses’
VOTE2VALUE = ‘1 Horse Sized Duck’

We can now test our changes and launch the application locally:

Now We Know It Works: Let’s Launch It to the Cloud!

First, use the command line “login” argument to associate your CLI to your Azure subscription.

az login

Next, we’ll create a Resource Group (to contain our work in Azure) and an App Service Plan (A FREE sku since we’re just launching a simple voting app and don’t need to worry about scaling at this time.):

az group create --name serverlessWorkshop --location eastus
az appservice plan create --name myAppServicePlan --resource-group serverlessWorkshop --sku FREE

Now, we need to create the Voting App in Azure. We’re also setting the method of deployment to be a Git Push at this time. (Note: The App Name will be part of the URL, so keep that in mind when naming your app.)

az webapp create --name icebreakerpoll --resource-group serverlessWorkshop --plan myAppServicePlan --deployment-local-git

At this point, we can verify our App has a live URL by visiting the defaultHostName value:

We’re almost done! Let’s set a few more things and see our poll live!

We need to set our Python Version and set a default path in App Service so it finds the right files for the environment.

az webapp config set --python-version 3.4 --name icebreakerpoll --resource-group serverlessWorkshop
az webapp config appsettings set --name icebreakerpoll --resource-group serverlessWorkshop --settings ENVIRONMENT=production

Lastly, we’ll need the Git URL. It was shown back when we created the Web App (az create …) as deploymentLocalGitUrl, but in case you’ve not it handy, you can get the URL again:

az webapp deployment source config-local-git --name icebreakerpoll --resource-group serverlessWorkshop --query url --output tsv

Next, we’ll add a remote to git so Git knows the URL to which to push. This is a standard Git command and you could use “cloud” instead of “azure” below; “azure” is just a short name for us to reference.

git remote add azure https://2018AHEADDEMO001@icebreakerpoll.scm.azurewebsites.net/icebreakerpoll.git

Here comes the best part: Let’s push code and have Azure create a containerized microservice in the cloud with our app—all in one step!

git push azure master

This step will prompt you for your password created earlier.

Let’s check our app!

Oh no! It’s reverted to the former values. Why?

When we tested locally, we never committed our changes. We can verify this with a Git command (diff):

Let’s change it and push. This will show how we can modify a live running containerized web app:

git add -A
git commit -m "<commit message>"
git push azure master

Testing again, we can see our changes are live:

Next Steps

In my next post, I’ll cover how to set up CI/CD pipelines in a free VSTS account to automate deployments from a given branch, as well as to how to properly secure this to just our user base.

Clean Up

Even though our web app is in the free tier, it’s best to clean up our deployment when done. I prefer using the portal, as I get a visual confirmation that all items have been deleted.

Go to portal.azure.com and find your resource group. Using the ellipses at the end, you can click and delete the group:

You can also go into the Resource Group and sanity check that it is indeed free:

Our Expertise in Azure

Whether it’s blind spots in areas of costs and inventory, or configuration missteps, or surprises at the number of tools required for successful deployments in the enterprise, the move to Azure goes far beyond swiping a credit card.

At AHEAD, we also don’t consider the public cloud as an end state, but as a new way of operating. So, we created our Public Cloud Operating Model to help clients oversee where apps run, where data lives, and how services get consumed.

Get in touch to set up a briefing to learn more about how you can leverage our industry experts and next-gen solutions to accelerate your evaluation process and emerge with a comprehensive cloud strategy.