In this tutorial, you will learn how a very simple application is developed, deployed to the cloud and set up for automatic deployment.
In order to work through this tutorial you will need to take the following preparation steps.
In order to obtain the source code of the application and share your changes you will need the git
command line tool installed on your computer. You can install it by following these instructions.
In order to run the application you will need Node.js installed on your computer. You can install it from this site.
For deploying the application to the cloud we will use the serverless
tool. You can install it by typing:
npm install -g serverless
When working with source code and configuration files, a normal text editor like Notepad is too clumsy to work with. Instead, we would like to have an editor which knows the syntax of our programming and configuration languages and can help us when making changes. A good editor to use is Visual Studio Code. Maybe you already know another one. Feel free to use it, if it is easier for you!
Our application is stored on Github. Navigate to the signup page to create your Github user. Once you have you user, you need to upload your SSH key by following these instructions.
Now you are ready to get a copy of the source code of our application. You can do that by creating a suitable work directory somewhere on your computer, changing to that directory and then entering the following command:
git clone [email protected]:bespinian/cowsay-in-the-cloud.git
You should now see a directory cowsay-in-the-cloud
in your current directory. If you enter that directory you will see all of the code and configuration needed for our little application.
In order to run our application we need to first install all of the libraries which the application needs:
npm install
Next we can type the following command to start the application:
npm start
Now that the application is running you can go to the browser and navigate to http://localhost:3000 to see the output. This is what you should be seeing:
________________________
< Mooooh from the cloud! >
------------------------
\ ^__^
\ (oO)\_______
(__)\ )\/\
U ||----w |
|| ||
You can now try to make some changes to the application. For this purpose, you can edit the file cowsay.js
. Try changing the message which the cow says. You can even change the way the cow looks or select an entirely different animal. Have a look at the documentation on how to do this.
Until now you have executed the application on your own machine. This is great for trying things out when you are making changes. Now, let's have a look how you would deploy the same application the cloud, make it available for others to use and ensure that it will keep working even if thousands of users were to use it at the same time.
We will use the serverless
tool to deploy the application in the cloud. In order for this tool to be able to access the cloud, you need to create some access credential for it. Use the following steps to achieve this:
- Navigate to https://aws.amazon.com/console/ in the browser.
- Press on the Sign In button.
- Enter the access credentials you received from your tutor.
- Click on your user name in the top right of the screen and then on
My Security Credentials
. - Press the button
Create access key
and download the CSV file. - Go to the shell an set the environment variable
AWS_ACCESS_KEY_ID
to the access key ID. - Set the environment variable
AWS_SECRET_ACCESS_KEY
to the secret key. - Set the environment variable
AWS_REGION
toeu-central-1
.
Your environment is now set up.
You can now deploy your version of the application with the following command:
serverless deploy --stage dev-<your name>
This will set up a new instance of the application named after you. You can also delete your application from the cloud by typing:
serverless remove --stage dev-<your name>
We do not want to keep repeating these steps manually every time we have a new version of our application, so there is a pipeline set up in the GitHub repo of the application. When you are ready you can push your change to the repo's main
branch and watch the pipeline re-deploy the application. First check your changes:
git status
git diff
If you are satisfied, stage your changes:
git add .
The commit them:
git commit
Then push them to the repo on GitHub:
git push
If you navigate to the actions
tab in GitHub you can see that the pipeline starts running and re-deploys the application with the changes you have just pushed.
Congratulations!