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
URL
https://www.comparethecloud.net/servers/serverless-best-practices-in-software-development/Original Source Link
Reviews
Comments
Most Recent Articles
- Oct 23, 2024 Cost to Build Music Streaming App in 2025 by Anita Shah
- Oct 21, 2024 Blog Topic- How Do Cyber Security Firms Utilize Advanced Technologies to Counter Threats? by securty
- Oct 21, 2024 Unlocking Business Efficiency with AI-Driven Software Development by rskbusiness
- Oct 14, 2024 Node.js Unleashed: A Deep Dive into JavaScript for the Server by Quickway Infosystems
- Oct 9, 2024 What Makes Angular and React Different Mainly? An Analysis of Comparisons by Quickway Infosystems
Most Viewed Articles
- 2823 hits Mit lokaler SEO Suchmaschinenoptimierung auf Platz eins! by BRIGHT DIGITAL
- 2481 hits What Is The Process Of Updating Garmin GPS Maps Free Of Cost? by Henry Ford
- 2019 hits Google Lighthouse- Auditing & Enhancing Shopify Theme Performance by Anuj Sharma
- 1889 hits How to Find Best Deals on www.amazon.com/code? by Patrika Jones
- 1620 hits How to change your Outlook password by larry felice
Popular Articles
In today’s competitive world, one must be knowledgeable about the latest online business that works effectively through seo services....
77514 Views
Are you caught in between seo companies introduced by a friend, researched by you, or advertised by a particular site? If that is the...
33028 Views
Walmart is being sued by a customer alleging racial discrimination. The customer who has filed a lawsuit against the retailer claims that it...
14055 Views
If you have an idea for a new product, you can start by performing a patent search. This will help you decide whether your idea could become the...
11257 Views
Statistics
Members | |
---|---|
Members: | 15673 |
Publishing | |
---|---|
Articles: | 64,357 |
Categories: | 202 |
Online | |
---|---|
Active Users: | 140 |
Members: | 3 |
Guests: | 137 |
Bots: | 5630 |
Visits last 24h (live): | 2194 |
Visits last 24h (bots): | 28004 |