fbpx

Cloud Powered Apps Walkthrough Part 1

We hope you enjoy this article, our idea is to provide a quick walkthrough as to how to easily put together a full CRUD API application with publicly exposed endpoints in the cloud.

Note: Based on past experience this walkthrough will take 4 hours or less.

WHY THE SERVERLESS FRAMEWORK?

Because the Serverless framework helps developers to configure all the infraestructure they need to quickly deploy and run their own Cloud-Powered Apps.

The good thing is, you are able to use managed services without using containers, ec2 instances or managing a lot of things by yourself.

For example, Terraform works really great if you want to spin up EC2 instances and RDS databases and you might want some containers and maybe an s3 bucket and a DynamoDB table, on the other hand, Serverless is focused around building functions were you compute models on lambda and use other server services to help you to accomplish your app goals.

Is not a secret that managing servers becomes tedious over time and time is resources and money… So saving ourselves time is pretty much the best thing we can do.

WHAT IS AWS?

Simply because it is the most mature Serverless Cloud Provider out there. We are talking about next-generation public cloud services that auto-scale and charge our budgets, only when used.

 

Ok, you can safely say now we are ready to gain free, hands-on experience with all the AWS platform services and resources available for you.

THE PROJECT APP

Let’s create a root directory for this project:

mkdir -p ~/Sites/softon cd ~/Sites/softon

If you don’t have experience with the Homebrew Package Manager, just don’t be afraid, it’s super easy to install and manage:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Once the installation is complete, go and install all the packages you are going to need to develop this Cloud-Powered App:

brew install nvm \
awscli \
serverless \
awslogs \
awscurl 

Sweet! Now is the perfect time to use Brew Cask to install a couple of graphical applications we might need later:

brew cask install adoptopenjdk \
dynamodb-local \
nosql-workbench-for-amazon-dynamodb

Add NVM_DIR to your shell settings

Edit your ~/.zshrc or file:

code ~/.zshrc

Now add the following lines of code:

export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ]  "/usr/local/opt/nvm/nvm.sh"
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ]   "/usr/local/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

Here we go, let’s;s use our shell’s built-in source command to reload the ZSH Shell settings:

source ~/.zshrc

Discover the power of the SLS CLI Tool

If you have questions about how to accomplish something using the SLS CLI tool, –help is your answer:

sls info --help

You should see something like:

--stage / -s ....................... Stage of the service
--region / -r ...................... Region of the service
--verbose / -v ..................... Display Stack output
--app .............................. Dashboard app
--org .............................. Dashboard org
--config / -c ...................... Path to serverless config file

You should try:

sls config --help
sls config credentials --help

sls deploy --help

Add your own IAM Admin User

We are going to create an IAM Admin User to:

  • Access to your AWS console.
  • Make API calls to AWS.

Note: Adding an IAM Admin User offers an extra layer of security to your AWS Root Account.

Here’s an example how you can configure the appadmin AWS Profile:

sls config credentials \
--provider aws \
--profile appadmin \
--key AKIAXOQZTFKW6AH4MFKI \
--secret qkONXFBWdY80Xsn9EbzVXBE5S77ZRzi/pBtBm9KE

Using profiles with the AWS CLI

To use a named profile, add the --profile profileName option to your command.

aws iam list-access-keys --user-name appadmin --profile appadmin
{
    "AccessKeyMetadata": [;
        {
            "UserName": "appadmin",
            "AccessKeyId": "AKIAXOQZTFKW6AH4MFKI",
            "Status": "Active",
            "CreateDate": "2020-05-24T23:26:45+00:00"
        }
    ]
}

Please install NodeJS 12

Nodejs Runtimes

Clone the SLS Demo API

Its time to pull down a full copy of the Serverless Stack Demo API at GitHub, including all the branches and versions of every file and folder available for that remote repository.

git clone https://github.com/AnomalyInnovations/serverless-stack-demo-api.git app

cd app

code .

Install all the packages it depends on

npm install

Deploy your SLS Demo Stack

Deploy helps you to provision your AWS Lambda Functions, Events and infrastructure Resources safely and quickly and you can always specify the profile which should be used via the –aws-profile option like this:

sls deploy --aws-profile appadmin

# OR

sls --aws-profile=appadmin deploy -s dev -r us-east-1

Get your deployed stack information

Via CLI TOOL

Via AWS Console

Learn more about Cognito

Please register a user in a specified user pool and create a user name, password, and user attributes for that specific user.

Create and list content

What do you think now about Serverless?

Please share your thoughts, I’d be happy to answer any questions you may have.

¡Happy Hacking!