Skip to content

austinloveless/AWS-API-MU

Repository files navigation

AWS - Serverless API

Powered by the Serverless Framework. The most widely adopted tool kit for building serverless applications. serverless image

Why go Serverless

Low maintenance required, you deal with your own application code and nothing else. It’s cheaper to run serverless applications because you are effectively only paying per request. So when your application is not being used, you are not being charged for it. See more HERE Finally, the ease of scaling is thanks in part to DynamoDB which gives us near infinite scale and Lambda that simply scales up to meet the demand.

Stay in touch on Slack and tell us what you thought of the course Here!

Table of contents

Who is this for?

This is meant for developers that would like to build serverless applications. Or for people who are looking to get more into infrastructor and the business side of cloud computing. It's meant to serve as a resource for learning about how to build and deploy serverless applications. Also this is catered solely towards JavaScript developers for now.

Let’s start by looking at what we’ll be covering.

What does this cover?

This is a Serverless API for a Todo List written completely in JavaScript. It is a relatively simple application but I am going to address the following requirements.

Basic CRUD Capability

  • The ablility to Create Todos
  • The ability to Get a list of all Todos.
  • The ability to Get a Todo based on an id.
  • The ability to Update a Todo based on an id.
  • The ability to Delete a Todo based on an id.

picture

End Product

Requirements

You will need Node v8.10+. You also need to have basic knowledge of how to use the command line, Git/Github, and JavaScript.

Technologies and Services

We’ll be using the following set of technologies and services to build our Serverless API.

How to get help?

Join the Meetup slack workspace and post your question in the aws-help channel. Slack

AWS Account Creation

First let's get started by creating an AWS (Amazon Web Services) account. Of course you can skip this if you already have one. Head over to the AWS homepage and hit the Create a Free Account and follow the steps to create your account.

aws homepage

Next let’s configure your account so it’s ready to be used.

Getting Setup with AWS Services

Create an IAM User

iam image Amazon IAM (Identity and Access Management) enables you to manage users and user permissions in AWS. You can create one or more IAM users in your AWS account.

In this section, we are going to create a new IAM user for a couple of the AWS related tools we are going to be using later.

Follow the instructions for Creating an IAM user HERE

Install the AWS CLI

To make it easier to work with a lot of the AWS services, we are going to use the AWS CLI.

The AWS CLI needs Python 2 version 2.6.5+ or Python 3 version 3.3+ and Pip. Use the following if you need help installing Python or Pip.

Now using Pip you can install the AWS CLI (on Linux, macOS, or Unix) by running: sudo pip install awscli Or using Homebrew on macOS: brew install awscli

If you are having some problems installing the AWS CLI or need Windows install instructions, refer to the AWS CLI install instructions.

Add Access Key to AWS CLI

We now need to tell the AWS CLI to use your Access Keys from the IAM section. It should look something like this: Access key ID AKIAIODSFSFFBGDNN7EXAMPLE Secret access key wJadsfXUtsfsI/K7MDENG/bPxRfiCYEXAMPLEKEY

Just run the following command in your terminal and enter Access Key and your Secret Key ID when asked. aws configure

For Default region name put us-east-1 that is the Northern Virgina region, and leave the Default output format as is.

Create a DynamoDB Table

dynamodb image To build our Todo API, it makes sense that we first start by thinking about how the data is going to be stored. We are going to use DynamoDB to do this.

Follow the instructions for Creating a DynamoDB Table HERE

Building the API

lambda image We are going to be using AWS Lambda and Amazon API Gateway to create our API. AWS Lambda is a compute service that lets you run code without provisioning or managing servers. API Gateway makes it easy for developers to create, publish, maintain, monitor, and secure APIs. We are going to use the Serverless Framework to help us with it.

The Serverless Framework will enable us to deploy backend applications as independent functions that will be deployed to AWS Lambda. It also configures AWS Lambda to run code in response to HTTP requests using Amazon API Gateway.

Install Serverless Framework

Run the following to globally install Serverless. npm install serverless -g

Walk Through the Project

I already have the API built in this Respository so lets clone this repo and walk through it.

  • Clone this repository on your local machine. git clone https://github.com/austinloveless/AWS-API-MU.git
  • Go into the directory that you just cloned. cd AWS-API-MU

NOTE There are two branches a master branch and an ES5 branch. If you are a beginner I would look at the ES5 branch. For ES5 Syntax

  • After cloning the repo and cd into it run the command git checkout ES5
  • You should now be in the ES5 branch And can follow along from there.

Running the API Locally

In the Root of your Project

  • Run the command npm install to install the NodeJS packages
  • Now In your project you should see a Handlers folder and a Mocks folder.
  • The Handlers folder is where your functions are for the API.
  • To Test the functions run the command serverless invoke local --function <function name ex: createTodo> --path mocks/<mock name ex: createTodo-event.json>
  • This will run your function and pass in the json object to test the function.
  • If functions pass you should get a 200 success code with the response and if it fails you should get a 500 error code.
  • To test this locally with API Gateway check out Serverless Offline.
  • There are comments throughout the code explaining the logic

Deploying the API

In the Root of your Project

  • Run the command serverless deploy to deploy your project
  • Run the command serverless deploy function --function <function name> to deploy a single function
  • You can see Serverless deployed a Cloudformation Template deploying your services onto AWS.
  • Now in your AWS account you can go see the deployed Lambda functions and the API Gateway API.
  • You should see something like this in your terminal

deploy image

Building From Scratch

Below is how to start the project from scratch and build your own API.

  • In your working directory create a project using a NodeJS starter. serverless install --url https://github.com/AnomalyInnovations/serverless-nodejs-starter --name todo-app-api
  • Go into the directory for our API project. cd todo-app-api
  • From here you can see the basic NodeJS starter template and start writing your own API.

Extra Resources

  • If you are looking to get a certification I would use AcloudGuru. They have some of the best resources for getting a certification.
  • If you are confused about a topic the Docs can be a good place to find information.
  • I would also highly recommend using the AWS FAQs for a quick answer to questions you may have.

aws-todo-client

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published