Code Deployment with Serverless Application in AWS

Vikash Kumar
Bits and Pieces
Published in
7 min readMay 28, 2020

--

The new buzzword in town, Serverless, has been getting much attention from both the rookies and pros in the technology world. Due in part to how cloud vendors, such as the AWS or the Amazon Web Services have hyped it, from meetups to conferences to blog posts to just about anywhere. Nonetheless, serverless is not only about the hype, but also about ideal business implementations.

What is Serverless?

Serverless is a cloud computing execution model wherein allocating and provisioning of servers are managed by the cloud server dynamically. A serverless app runs in event-triggered stateless compute containers managed fully by the cloud provider. The pricing is based on the executions made instead of the pre-purchased compute capacity.

Why use Serverless computing?

There are several advantages to serverless computing compared to the traditional cloud-based or even a server-centered infrastructure. Serverless architectures, for a lot of developers offer more flexibility, greater scalability, and a faster release time, all at minimal cost. Developers need not worry on making a purchase, provision and management of backend services.

What is AWS?

The Amazon Web Services is a secure cloud services platform that offers storage of database, compute power, delivery of content, as well as other functionality to help a business grow and scale. Simply put, AWS enables you to do these things:

- Store all files on the cloud securely for access anywhere.

- Running web and app servers in the cloud for dynamic websites hosting.

- Deliver dynamic and static files worldwide fast using CDN or Content Delivery Network.

- Send customers bulk emails

- Use managed databases, such as Oracle, MySQL, SQL Server, and PostgreSQL for storing information.

6 Easy steps to deploy a Serverless App in AWS

You would need to set up some things before getting started. An important consideration: Node.js is used as the run-time environment. Most developers have experience using JavaScript, that’s why Node is the ideal tool for this particular case.

The Serverless framework is by far the best tool, which leverages the CloudFormation of AWS for automating the making of the needed resources for apps to run in the cloud.

Step One. Serverless framework installation.

Take note: The basic guide assumes you have more than just basic JavaScript knowledge. However, if you are entirely new to JavaScript or Node, it may not be a good idea to jump straight to the serverless framework. You must first have to m aster the basics.

You would see something the same as the following when you have successfully accomplished the above step.

There is also an in-depth information regarding Serverless from the official website.

Step 2: Setting up the AWS Access Keys.

You would need both aws_secret_key and aws_key set up in the host machine for authentication with AWS, and letting you go to deployment. Do the following steps to get the needed AWS Keys.

The Great Finish!

Time to set up the ‘main attraction’.

Step 3: Making of the Serverless App

You could make this command:

Copy the code then paste it on the file you just made.

Step 4: Deploying the Serverless Application.

Invoke the following command to accomplish this.

Step 5: Make certain that everything works.

Test the API with the use of Postman or some other tool that performs in the same way.

That’s a successful deployment of your first Serverless application in AWS. There may be some concerns with permission during the process of deployment, but that’s an easy fix. The framework would tell you what permissions you exactly have to add.

Added Bonus: Serve Offline

The Serverless architecture has plenty of available robust plugins on npm, like the following:

- Serverless-dynamodb-local

- Serverless-webpack

- Serverless-offline

- Serverless-finch

Step 6: Serve services offline and locally invoke the API.

In the plugins section, you can add the serverless-offline in the serverless.yml file. It should appear similar to this:

Although the Serverless architecture could be intimidating initially, with the right tools, app deployment could be accomplished.

The Pros of the Serverless Computing

  1. No server management necessary. Even though ‘serverless’ computing actually occurs on servers, developers do not ever have to deal with the servers, since they are managed by the vendor. This could minimize the necessary investment in DevOps, which lessens costs and frees up developers to build and expand the apps without server capacity constraints.
  2. Reduced cost by charging only the server space used. Developers are charged only for what they use. When the backend functions are required by the serverless app, that’s when the code runs automatically and scale up as required. The provisioning is in real-time, dynamic and precise. Some services are very exact that they divide charges down to 100-millisecond increments.
  3. Fast updates and deployments are possible. With a serverless architecture, there’s no need to upload code to servers or perform a background configuration to release an app’s working condition. Developers get to update code bits fast and release a new product. Moreover, they could upload code one function at a time or all at once. This is due to the fact that the application is not a single monolithic stack. It is instead a collection of provisioned functions by the vendor.
  4. Serverless apps are naturally scalable. Automatically, an app created with a serverless infrastructure would scale up with the increase of usage or the rise of the user base. If a function requires running in numerous instances, the servers of the vendor would start up, run and end them as needed.
  5. Code could run nearer to end users, minimizing latency. The code could run anywhere because it’s not hosted on an origin server. Thus, depending on the vendor, it’s possible to run app functions on servers nearer to the end user, which reduces latency since requests from a user need not travel all the way to the origin server.

The Cons of Serverless computing

  1. More challenge in debugging and testing. It’s hard to replicate the serverless space to see how code actually performs once deployed. The debugging task is more complex since developers have no visibility the backend process, and since the app is divided into smaller, separate functions.
  2. New security concerns are introduced. When vendors run the whole backend, it may not be possible to vet the security in full, which could be a problem for apps handling sensitive or personal data.
  3. Framework is not built for long-running processes. This restricts the types of apps that could run in a serverless architecture in a cost-effective manner. It could probably cost more since providers will charge for the duration the code is running, with processes that could take long compared to a traditional one.
  4. Could have performance impact. A serverless code, since does not run constantly may have to ‘boot up’ when used. The startup time could decrease performance. If a code however is used on a regular basis, the serverless provider could have it ready for activation. A request for the ready-to-go-code is called the ‘warm start’. On the other hand, a request for code that’s not been in use for some time is called the ‘cold start’.
  5. Vendor lock-in risk. Enabling a vendor to provide all backend services could inevitably boost vendor reliance. If a switch is necessary, it could be difficult to set up a serverless architecture with one vendor. This is because vendors offer slightly different workflows and features.

Who should use a Serverless Framework?

Software Developers or Software development companies like Tatvasoft who want to minimize their go-to-market time and create flexible, lightweight apps that could be updated fast or expanded could greatly benefit from a Serverless computing. The architectures lower app cost that witness inconsistent use, with peak periods changing during less to no traffic. For these apps, buying a server or a block of servers that run constantly and are always available even if not used could be a waste of resources.

A Serverless setup instantly responds when needed and does not incur costs when unused. Moreover, developers who want to push a few or all app functions close to end users for lower latency would need at a partially Serverless architecture at least, because doing so will necessitate moving several process from the origin server.

Publish and Reuse React Components with Bit

Publish independent React components from any codebase to a single component hub. Use Bit to document, organize, and even keep track of component updates and usage.

Share components with your team to maximize code reuse, speed up delivery and build apps that scale.

Example: exploring React components published on Bit.dev

--

--

Manager at software development company Tatvasoft.com. He also featured his bylines at many other publications like Entrepreneur, YourStory and many more.