Why I often use AWS lambda and serverless architecture
Why I Like Using Serverless and Lambda Functions
In this section, the speaker discusses the benefits of using serverless architecture and Lambda functions for deploying applications.
Benefits of Using Lambda Functions
- Lambda has been used at work for the past four or five years to deploy the entire application, including APIs and asynchronous functions.
- Lambda provides built-in features that help with maintainability and monitoring of software, reducing the developer's focus on these aspects.
Challenges with Traditional Deployment Methods
- Traditional deployment methods require an executable file to run a web server like Express or Nest.js.
- Hosting on a VM requires additional setup for memory management, crash recovery, and scaling.
- If a server crashes, all concurrent connections are lost, resulting in data loss.
- Scaling an Express service on a single VM has limitations and may require horizontal scaling.
- Monitoring production logs and resource usage becomes complex when managing your own VM.
Benefits of Using Lambdas for Deployment
- A "monolambda" approach involves putting the entire Express code into a single Lambda function.
- Each execution of a Lambda function runs in isolation, ensuring that exceptions only affect individual requests without impacting others.
- Scaling Lambdas is easy as they automatically provision containers based on traffic volume.
- Versioning allows quick rollbacks in case of critical bugs.
- Lambdas integrate well with other AWS services for seamless integration within an AWS environment.
Benefits of Using Lambdas
In this section, the speaker discusses the benefits of using Lambdas, including increased timeout limits and built-in monitoring.
Increased Timeout Limits
- Lambda allows for longer timeouts compared to other services.
- The default timeout is 10 seconds, but it can be increased up to 15 minutes.
- This is beneficial for handling complex computations or when not limited by API Gateway.
Built-in Monitoring
- Lambdas come with built-in monitoring capabilities.
- Request invocations are monitored, providing information on request duration and cost.
- CloudWatch logs provide detailed information about Lambda functions and can be forwarded to Elasticsearch or Kibana for better log parsing.
- Log Insights offers a more robust way to search through logs using query syntax.
Metrics and Monitoring
- The monitor tab displays recent invocations, their durations, errors, throttles, and other metrics.
- Metrics provide insights into invocation counts and performance over time.
- These built-in monitoring features make it easier to track and analyze Lambda functions compared to rolling your own logging solution.
Downsides of Using Lambdas
In this section, the speaker highlights some downsides of using Lambdas such as cold starts and memory limitations.
Cold Starts
- Cold starts can be an issue with Lambdas.
- When a Lambda function is invoked after being idle for some time, it takes a few seconds to start up. This delay may impact user experience if load time is critical.
- However, as traffic increases, more warm lambdas are available which reduces the likelihood of encountering cold starts.
Memory Limitations
- Lambdas have a memory limit of 250 megabytes (MB).
- Certain tasks like PDF generation with libraries like Puppeteer can consume a significant portion of this limit.
- When hitting memory limits, alternative approaches like using containers or other services may be necessary.
Considerations and Cost
- Despite the downsides, Lambdas offer cost advantages as they are only charged per invocation.
- For low-latency and critical applications, it may be worth considering alternatives like self-running services or containers.
- The decision to use Lambdas should be based on the specific requirements and trade-offs of the project.
Additional Benefits of Using Lambdas
In this section, the speaker mentions additional benefits of using Lambdas such as easy integration with API Gateway and cost efficiency.
Integration with API Gateway
- Lambdas can be easily integrated with API Gateway to create a fully functional REST API.
- Custom domains can be used for hosting the Express service through API Gateway.
Cost Efficiency
- Using Lambdas is cost-effective as you are only charged per invocation.
- There is no need for dedicated servers that incur monthly charges even when not in use.
Considerations for Workload
- For workloads involving frequent requests or cron jobs, it is important to consider the overall costs and performance trade-offs between Lambdas and other solutions.
- Crunching the numbers will help determine which approach is more suitable for specific workload requirements.
Overview of Using Lambdas
In this section, the speaker provides a brief overview of why they enjoy using lambdas in their programming. They also mention various ways to engage with their content and community.
Why I Like Using Lambdas
- The speaker enjoys using lambdas in their programming.
- They find lambdas to be a powerful tool for certain tasks.
- Lambdas allow for concise and expressive code.
- The speaker encourages viewers to leave comments, like, subscribe, and click the bell icon for notifications.
- They have a Discord channel where viewers can directly interact with them and ask questions.
Please note that the timestamps provided are approximate and may not align perfectly with the transcript.