Build a professional serverless web service with AWS CodeStar

If you have ever tried building a web service using AWS services, you might have found it quite overwhelming to get started with. There are a plethora of different build tools, frameworks, etc. Plus, combining every piece into a CI/CD deployment cycle is not a simple task, even when using AWS tools, which greatly simplify the steps needed. AWS CodeStar aims to fill this current pain, by making it extremely simple to build and deploy a serverless web service. It can be used for more than this, but since web applications are my current cup of tea, I will show the steps necessary to get a serverless web services project running with AWS CodeStar.

AWS CodeStar Landing Page (https://aws.amazon.com/codestar/)

After login into the AWS Console, we have to go into the AWS CodeStar dashboard. From there we click on the big blue button that says “Start a Project”.

AWS CodeStar console dashboard welcome page.

The first step is to create a new template. For this example, I’ll choose the Express.js over AWS Lambda.

AWS CodeStar template selection pane. Filtered to only show “serverless” templates.

Then we set up a name for it. I am going to be incredibly original and name my project “web-service”. Take into account that AWS CodeStar will offer to administer the AWS resources for ourselves by creating assigning itself a role with enough permission. We can opt-out of this by deselecting the box at the end of the form.

AWS CodeStar wizard form.

If we investigate what the form is actually presenting us, we’ll see what AWS CodeStar is going to set up for us.

First, it will initialize a new repo on AWS CodeCommit for us. If you have never heard of CodeCommit, it provides a service similar to GitHub but all the repositories are private by default. The free tier allows up to 5 active users, 50 GB per month of traffic and 10000 git requests per month. It is a great tool if you need to keep your code private, which is usually the case when you are working in an Enterprise environment.

Next, is AWS CodeBuild. This tool from AWS was designed to manage all the steps to build our source code. It is great to run tests, build our code, and pipe its results into a CI/CD workflow. For our Node-based project, it will bundle our code, run our test them, and pass the build to AWS CloudFormation for deployment.

The last step of the chain is to set AWS CloudWatch to monitor all the pieces of our project.

Then we are offered a choice to integrate our project into our development environment. There are choices of the AWS Toolkit to use with Visual Studio or Eclipse. Since I only use a text editor for all my coding, I prefer the third option, which is to handle the project from the command line.

AWS CodeStar project edit tools.

Clicking each of the options will show a tutorial with the steps needed to integrate the project with our tools. The command line option only asks you to clone the created repository to your machine. You’ll find very thorough explanations on how to clone a CodeCommit repository on your specific OS.

After clicking “Next” we are done with the setup, and we are greeted to our project monitoring dashboard. There are a lot of widgets we can take advantage of. We can see our project history, its history, our continuous deployment pipeline, etc. It also provides quick links to configure the main parts of our project, like its repo, build tools, deploy tools, pipeline setup, and team management. Here is a list of all the resources that were created for us.

List of AWS CodeStar project created resources.

After cloning the project to our local machine we’ll see a list of files. The buildspec.ymcontains all the build information of our project. By default, the app will just run npm install to install the project dependencies and then it will generate a template file to run through CloudFormation to deploy the app.

The index.jsand app.jsfiles are already set up to let express.jsbased APIs to run over AWS Lambda. You shouldn’t need to change anything from the index.js file, just edit the app.js file to build your web service.

Lastly, we have the template.yml file, which is a CloudFormation template our default infrastructure setup. We can modify this file to handle our entire application infrastructure on AWS, without having to interact anymore with the AWS console or its cli.

To see how the project is working we can update the app.js file, commit the changes, and then push to origin to trigger the continuous deployment pipeline.

app.get('/', function(req, res) {
  res.send({
    "Output": "Hello World from AWS CodeStar!!!"
  });
});
git commit -m -a "testing CD pipeline"
git push

After a few seconds on the project dashboard, we should see the pipeline start working.

Continuous deployment status widget.

When the deployment is done, we can check that the update was successful by checking our API Gateway endpoint. It should know show are greetings from AWS CodeStar.


With all this setup, we only need to start working on our application without having to worry much about the operation side of it. For me, this tool has been great on little projects, and I am currently working to set up some of my daily work development projects on it. Maybe in the future, I’ll create a follow-up to this article, with some experience on running it on an existing working application with a current big audience.

As always, thank you for taking the time to read this article. I am open to any feedback or question you have for me.