• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Codemotion Magazine

Codemotion Magazine

We code the future. Together

  • Discover
    • Live
    • Tech Communities
    • Hackathons
    • Coding Challenges
    • For Kids
  • Watch
    • Talks
    • Playlists
    • Edu Paths
  • Magazine
    • AI/ML
    • Backend
    • Frontend
    • Dev Life
    • DevOps
    • Soft Skills
  • Talent
  • Partners
  • For Companies
Home » DevOps » Cloud » Building a Stateful Cloud App on Nimbella or AWS
Cloud

Building a Stateful Cloud App on Nimbella or AWS

Building a stateful Cloud App; here's a comparison of the user experience in Nimbella and AWS, with a handy How-to guide.

Last update November 27, 2020 by Michele Sciabarra

Cloud Computing
Table Of Contents
  1. What sort of Stateful Serverless Cloud App am I going to build?
  2. How should the code files be arranged?
  3. How can an App be made Stateful for the Cloud?
  4. Static Assets…how can a Stateful App that has these be deployed to the Cloud?
  5. So, what does that mean for me?

Building serverless cloud applications? There’s a simple way to do that! This article compares the user experience of Nimbella and Amazon Web Services when creating a voting app, from a developer‘s point of view.

What sort of Stateful Serverless Cloud App am I going to build?

For the purposes of writing this article, I built a voting app that allows users to say whether they prefer cats or dogs. Because the data input by the user needs to be saved between sessions for later re-use, this needs to be a stateful app.

Building this app requires two things.

  1. A frontend that displays two voting buttons.
  2. Two cloud functions that save the application’s “state” by calling on key-value storage
A cat and a dog in a voting app
Dogs or Cats? Which do you prefer?

How should the code files be arranged?

Code file arrangements in Nimbella and AWS
Code file arrangements for Nimbella and AWS

First things first: let’s look at how to organise the code before we look at the practical elements of launching the code in the Cloud.

Each of the systems illustrated above includes two folders for this project; one contains static content (Web) and the second stores cloud functions (Packages). The primary difference between the two systems lies in how they arrange the cloud functions.

In Nimbella, I simply create the cloud functions as two files (addVotes.js and getVotes.js).

If I use Amazon Web Services, the process is a little more complex. The first step is the creation of separate folders for each cloud function.  Next, the JS files are added, and their dependencies are included in each folder. Finally, the zip file with its node-modules folder, the JS file, and the package.json are added to complete the process.

How can an App be made Stateful for the Cloud?

Making an app stateful - the process in Nimbella and AWS
Making an app stateful: diagrams for Nimbella and AWS

Key-value storage is necessary to make a stateful app – it saves the votes already cast, and presents the running totals when the page is refreshed. Again, Nimbella and AWS achieve this in different ways.

Nimbella

  1. Add Redis (key-value storage) to the project. To this end, create a new project template by running the following command:
    nim project create ProjectName
  2. Call Redis from your functions. To this end, first import nim, and then import Redis from it within the function. Finally, add the code logic that makes Redis either update the vote totals, or return the current voting numbers (see image below)
  3. Deploy stateful functions to the Cloud. Ensure your functions are properly located within the Packages folder, then run the following command:
    nim project deploy ProjectName

The services I need to achieve a stateful app are all readily available and in place in this system. Because of this, there’s no service set-up to carry out – all I have to do is call the required services using code logic.

To increment voting numbers, I used code similar to the following:

Code for incrementing voting numbers
Code used to increment voting numbers

Amazon Web Services

Making a stateful application in AWS involves a number of steps. Using this system, I created stateful key-value storage like this:

  1. Deploy a Redis (key-value storage) cluster on Amazon Web Services:
    1. Select Redis from the AWS ElastiCache service
    2. Input name, version, port, parameter group, node type, and the number of replicas desired in the Redis settings
    3. Nominate the VPC your Redis cluster should be connected to
    4. When this process is complete, keep the Primary Endpoint – it’s important in the next step
  2. Deploying EC2 on Amazon Web Services:
    1. Use the service tab to look for EC2. Don’t forget to choose your region;
    2. Open “Launch Instance”
    3. Select the type of instance you need
    4. Configure your instance (N.B., always use the same VPC that you used for ElastiCache)
    5. Add your Storage
    6. Attach tags
    7. Configure the Security Group & check what you have done so far
    8. Connect the SSH to your EC2 instance before installing the Redis CLI
    9. Connect the Redis instance via Redis CLI. Don’t forget to include the primary endpoint of Redis (as previously mentioned, this is important!)
  3. Deploy Lambda functions on Amazon Web Services, then connect it to API Gateway:
    1. Find Lambda by using the service tab. Ensure the correct region is identified
    2. Create functions methodically. Working one by one, select “Author from Scratch”, the function’s name, and what type of code it uses (NodeJS, Python, etc)
    3. Using the same VPC as Redis, connect your functions. Check each one to be sure the correct ports have been chosen
    4. Connect your functions to API Gateway. Choose a trigger for the function, requesting an HTTP API as the trigger type. This will provide you with a URL that can be used to call your functions through your code

Static Assets…how can a Stateful App that has these be deployed to the Cloud?

Cloud deployment in Nimbella and AWS
Deployment to the Cloud with Nimbella or AWS

With your static web assets and cloud functions complete, you can finally deploy the entire app to the Cloud!

Deploying to the Cloud with Nimbella

If you’re using Nimbella, there’s no need to configure cloud storage for any front-end static assets, nor to configure a content delivery network (CDN) that will serve the app from the Cloud. This is because the configuration will be done for you – just issue the instruction that your code logic should be sent to the Cloud, like this:

  • Open your Command Prompt and run:
    nim project deploy ProjectName
  • Paste the URL that appears in your browser

Code needs updating in Nimbella? Another simple process: you just need to update the code, then run the following command:

nim project deploy ProjectName

Deploying to the cloud with AWS

  1. Choose AWS S3 in Service to begin creating an S3 bucket
  2. Click on the “Create Bucket” button and add the bucket’s name and region
  3. Add relevant files and folders to the S3 bucket
  4. After the files have completed uploading, click on “Static Website Hosting”
  5. Paste the Endpoint into your browser

Code updating in AWS? A little more time consuming:

  •  Start from scratch and rebuild the code
  •  Empty the bucket of all files before uploading your new version
  • Double-check that the static web host tab includes index.html

So, what does that mean for me?

Nimbella has made developing a stateful cloud app a lot easier by minimising architectural complexity and offering ready-to-go key-value and object storage as part of its system. This frees you and the developer up to centre your attention on code logic instead.

If you already have a stateful app that you would like to deploy to the cloud, you can try Nimbella out for free. Nimbella also has a Community Slack channel where you can get your questions answered and share your project with a community of fellow-enthusiasts.

To see the code used for this article, you can click here for Nimbella or here for the Amazon Web Services version.

facebooktwitterlinkedinreddit
Share on:facebooktwitterlinkedinreddit

Tagged as:AWS

Web Development and the Future of Progressive Web Apps
Previous Post
5 Rules of Engagement When it Comes to Data Visualization
Next Post

Related articles

  • Considering a cloud transformation?
  • How to Monitor Google Cloud
  • Amazon, Google, and Microsoft Take their Clouds to the Edge
  • How to Monitor Cloud Metrics For Scaling
  • Cloud computing remains a critical component of innovation
  • Terraform AWS: Up and Running in 25 Minutes
  • 6 Cloud Computing Skills Needed to Boost Your CV This Year
  • Goodbye to High-End PCs? How the Cloud is Changing Gaming
  • How to Optimise Configuration Management And Boost Security In the Cloud
  • How to Boost Technological Innovation and Agility in the Banking Sector

Primary Sidebar

The IT Industry in Italy: Trending Positions, Salaries, and Main Skills for 2022

Codemotion and Adecco’s guide to understanding the IT working environment in Italy. Download here:

Adecco Whitepaper IT Report

Latest

gRPC, REST, HTTP1, HTTP, HTTP2

GRPC Approach for Improved Software Development

Web Developer

Using the Twelve-Factor Methodology in Cloud-Native Microservices

Microservices

svelte, javascript frameworks, vue.js, angular

Svelte: Why Is It an Innovation to Javascript Frameworks?

JavaScript

blockchain, avascan, avalanche, defikingdom, subnet

How to Deploy a Subnet on Avalanche Blockchain: The Case of DeFi Kingdom

Blockchain

automation, security, cybersecurity

How to Implement a Security Testing Program For Web Applications

Cybersecurity

Related articles

  • Considering a cloud transformation?
  • How to Monitor Google Cloud
  • Amazon, Google, and Microsoft Take their Clouds to the Edge
  • How to Monitor Cloud Metrics For Scaling
  • Cloud computing remains a critical component of innovation
  • Terraform AWS: Up and Running in 25 Minutes
  • 6 Cloud Computing Skills Needed to Boost Your CV This Year
  • Goodbye to High-End PCs? How the Cloud is Changing Gaming
  • How to Optimise Configuration Management And Boost Security In the Cloud
  • How to Boost Technological Innovation and Agility in the Banking Sector

Footer

  • Magazine
  • Events
  • Community
  • Learning
  • Kids
  • How to use our platform
  • Contact us
  • Become a contributor
  • About Codemotion Magazine
  • How to run a meetup
  • Tools for virtual conferences

Follow us

  • Facebook
  • Twitter
  • LinkedIn
  • Instagram
  • YouTube
  • RSS

DOWNLOAD APP

© Copyright Codemotion srl Via Marsala, 29/H, 00185 Roma P.IVA 12392791005 | Privacy policy | Terms and conditions

  • Magazine
  • Events
  • Community
  • Learning
  • Kids
  • How to use our platform
  • Contact us
  • Become a contributor
  • About Codemotion Magazine
  • How to run a meetup
  • Tools for virtual conferences

Follow us

  • Facebook
  • Twitter
  • LinkedIn
  • Instagram
  • YouTube
  • RSS

DOWNLOAD APP

CONFERENCE CHECK-IN