Serverless Best Practices in software development

by Lucy Brudo on Jul 25, 2022 Software 439 Views

Serverless function-based compute platforms like AWS Lambda are built for scale. They automatically provision computing resources as needed and are designed to handle tens of thousands of requests per second. This makes them a great fit for modern web applications and APIs.

But “serverless” doesn’t mean you don’t have to think about servers or architecture anymore, or that you can completely ignore best practices used in software development. It just means you don’t have to worry about infrastructure management and scaling, so your focus can shift to building new features and delivering value faster, which is the ultimate goal of serverless.

Here are some best practices we’ve learned at Serverless over the past few years while building serverless applications on AWS Lambda.

What is serverless?

Serverless computing is a cloud-computing codeless execution model in which the cloud provider runs the server and dynamically manages the allocation of machine resources. Pricing is based on the actual amount of resources consumed by an application, rather than on pre-purchased units of capacity. It is a form of utility computing. The name “Serverless Computing” was created by Amazon Web Services (AWS) to describe AWS Lambda.

Serverless best practices

Start locally

From day one, this is the best practice for working with serverless code. If you can code it locally, you can likely deploy it to AWS Lambda and run it successfully in production. Start locally and build your function using the same language runtime and same SDK as you would use on Lambda and AWS. The role of Lambda is to execute your code on-demand, so focus on writing good code first and then start exploring how to deploy that code on Lambda.

Use 1 function per route

This will help in debugging and code maintenance. If you want to change the execution path of your API, you can do it by changing a single file instead of making changes to multiple files and routes.

Use error handling middleware

Anything can go wrong in your API request and you should be prepared for it. Your API might get a request that is not valid or an internal error can occur during the processing of the request. You should be able to handle these errors gracefully and inform the client about what happened and the possible next steps for them.

Manage code, not configurations

The serverless programming model requires a different approach to configuration management. Rather than managing configurations across all your services, you should manage code. You can use Lambda layers to do this. Layers allow you to separate concerns and reuse code across all the functions. As a best practice, use Lambda layers to manage shared dependencies like libraries, frameworks, SDKs, or runtimes. This approach also has the benefit of reducing deployment package sizes (and thus deployment times) because only changes in your function code need to be packaged and deployed.

Serverless best security practices

Deploy API gateways for security

API gateways are a standard feature of modern software architecture, and they have several important functions, including the handling of authentication and authorisation. API gateways provide a single point of entry for a variety of services and allow you to hide direct access to other downstream services. This can make it easier to work with third-party APIs and also provide some added security. If you are using an API gateway to connect with other services, be sure to use HTTPS protocols throughout so that you don’t accidentally expose sensitive data at any point in the process.

 

Properly Handling Secrets

To secure your serverless applications, you must focus on managing the secrets that your functions use. The first step is to avoid hardcoding secrets into the code itself. Hardcoded secrets are a security concern because they are visible to anyone who can view the source code. AWS Lambda provides a Secrets Manager that you can access from any function, and it makes it easy to rotate secrets without redeploying your application.

Limiting Permissive IAM Policies

When using a serverless stack, most of the permissions for AWS resources need to be set in an IAM role. In general, these roles should be given the least amount of permission needed to function properly. However, this can be difficult to accomplish with serverless functions because the code is not necessarily known at the time the role is created. Therefore, it is common practice to give a serverless function’s role full access to AWS resources.

 

Article source: https://article-realm.com/article/Computers/Software/25320-Serverless-Best-Practices-in-software-development.html

Comments

No comments have been left here yet. Be the first who will do it.
Safety

captchaPlease input letters you see on the image.
Click on image to redraw.

Reviews

Guest

Overall Rating:

Statistics

Members
Members: 16447
Publishing
Articles: 77,617
Categories: 202
Online
Active Users: 474
Members: 5
Guests: 469
Bots: 11796
Visits last 24h (live): 1399
Visits last 24h (bots): 33167

Latest Comments

Target Credit Card Login makes it easy and quick to manage your account. The secure online portal allows cardholders to view balances and transactions, make payments and monitor account activity...
amazon.com/code – Enter Your Gift Card or Promo Code with Ease! Have a gift card or promotional code? Just go to amazon.com/code and quickly redeem your code to add the balance to your account....
  Snow Rider rewards concentration and precise timing, as one mistake can instantly end the run and force a restart.
Having a reliable account portal is very important, and this is exactly what Target red Card Login offers. The platform offers easy access to account details and payment instruments, enabling...
Ready to stream? Just go to Amazon.com/mytv to activate your device with a few easy steps, and you'll be watching your favorite movies, TV shows and exclusive Prime Video content in no time!...
As someone interested in technology, I appreciate how IDEs simplify complex development tasks and make programming more accessible. Reading about the challenge of choosing the right IDE reminds me...
Yes, great US Military force. Also, in his post you have given a chance to listen about US Military. I really appreciate your work. Thanks for sharing it.  oak dining table
It's worth noting that Facebook Messenger offers several cool features like managing multiple accounts, integrating SMS messages, and even a secret conversation mode for added privacy. So, if...
Think of a friend who will not be intimidated by your request for something out of the ordinary. We have heard about every type of thing and done all of it in our Escort Delhi. She'll answer...
Our Delhi Escorts pick this work simply because they like it; and they feel fortunate to encounter genuine, interesting clients similar to you who can be trusted.  Hauz Khas Escort Escort...

Translate To: