Migrate AWS Lambda to the Lightning-Fast provided.al2 Runtime

AWS Lambda Apr 26, 2024

Are you a developer leveraging Go with AWS Lambda? At Halodoc, we’ve been on the forefront of using cutting-edge technology to improve health outcomes and service efficiency. As part of our continuous effort to enhance system performance and developer experience, we want to share some critical insights and guidance.

This blog post will walk you through the process of migrating your Go Lambda functions from the go1.x runtime to the provided.al2 runtime. Transitioning to provided.al2 not only boosts performance but also offers several other benefits that we’ve capitalised on at Halodoc.

Understanding Lambda Runtimes

Lambda runtimes play a crucial role in determining how your function code executes within the AWS Lambda environment. Essentially, a runtime provides a bridge between your function code and the underlying Lambda execution environment. Each runtime has its own set of dependencies, configuration requirements, and performance characteristics.

Why Migrate in the first place?

Well, it's essential to stay up-to-date with the latest updates and security patches, especially considering that the go1.x runtime is being deprecated in alignment with Amazon Linux 1's end-of-life. Although the scheduled end-of-life for Amazon Linux 1 was December 31, 2023, it's never too late to transition to the provided.al2 runtime. The migration process is relatively painless and offers a host of benefits."

Benefits of provided.al2 Runtime

The provided.al2 runtime offers several enticing benefits over its predecessor. Firstly, it supports running Lambda functions on AWS Graviton2 processors, providing up to 34% better price-performance compared to functions running on x86_64 processors. Who doesn't love better performance at a lower cost?

Secondly, the provided.al2 runtime boasts a streamlined implementation, resulting in smaller deployment packages and faster function invocation paths. This means quicker execution times and happier users.

Lastly, aligning Go with other languages that compile to native code, such as Rust or C++, the provided.al2 runtime positions Go as a first-class citizen in the Lambda ecosystem.

Migration Steps

The good news is that migrating to the provided.al2 runtime typically doesn't require any code changes. The only adjustments revolve around how you build your deployment package and configure your function. Here's a quick rundown of the steps required:

1. Compiling for provided.al2 Runtime: Start by compiling your Go code for Linux. Unlike the go1.x runtime, which allows any executable name, the provided.al2 runtime mandates using 'bootstrap' as the executable name. It's as simple as tweaking your build command:

Go build

2. Creating Deployment Package: Once you've compiled your code, zip it into a deployment package ready for Lambda:

build-package.sh

Challenges experienced during the migration process:

The primary challenge encountered during the migration of Go Lambda functions to the new runtime stems from:

  1. Unlike other language runtimes, the custom runtime for Go Lambda functions ignores the Handler parameter, which is typically used to determine the function's entry point, creating potential confusion and issues.
  2. The Lambda service does not verify the presence of the bootstrap entry point within the archive during deployment, leading to the possibility of deploying broken functions if this crucial component is not validated.
  3. If you encounter the error resulting from a missing bootstrap file, it will manifest as follows:
Bootstrap entry point error

Upon encountering this error, it is imperative to ensure that your deployment package includes the necessary bootstrap file at the root of the zip archive.

4.  During the migration process, we encountered challenges related to incorporating the wkhtmltopdf converter into Lambda functions. This problem arose due to the absence of essential libraries, notably libXrender.so.1, within the provided.al2 runtime environment.

To resolve this issue, we took the approach of uploading the required libraries to an S3 bucket and incorporating them into the deployment package during the zipping process. Despite these proactive measures, the error persisted, prompting us to delve deeper into finding potential solutions.

build-package.sh

Runtime execution details

Before migrating to provided.al2, it's essential to assess the performance improvements you can expect. By comparing execution metrics before and after migration, you can quantify the enhancements in terms of:

  • Execution Time: We conducted thorough performance testing and benchmarking, and we're thrilled to report an impressive improvement in execution time. After migrating to the provided.al2 runtime, our function execution time decreased by approximately 27%, showcasing the efficiency gains of the new runtime environment.
  • Resource Utilization: Our analysis of CPU and memory usage revealed significant improvements in resource utilization post-migration. With the provided.al2 runtime, we experienced approximately 33% better CPU utilization and 29% more efficient memory usage, ensuring optimal resource allocation and cost-effectiveness.
  • Invocation Frequency: Monitoring the frequency of function invocations provided valuable insights into our workload handling capacity. After migrating to provided.al2, we observed a remarkable surge in invocation frequency, indicating a 31% increase in our ability to handle concurrent requests seamlessly.

By conducting rigorous performance testing and benchmarking, we validated the tangible benefits of migrating to the provided.al2 runtime. These improvements not only enhance the overall efficiency of our Lambda functions but also contribute to a smoother and more responsive user experience.

Incorporating these insights into your migration strategy will empower you to make informed decisions and unlock the full potential of the provided.al2 runtime, ensuring your Lambda functions operate at peak performance levels.

Billing Considerations

It's worth noting the billing differences between the go1.x and provided.al2 runtimes. With go1.x, Lambda doesn't bill for time spent during function initialisation (cold start). However, with provided.al2, initialisation time is included in the billed function duration. But fear not; since Go functions initialise quickly and Lambda reuses execution environments, the added cost is negligible compared to the performance benefits gained.

Conclusion

Migrating your Go Lambdas to the provided.al2 runtime is a smart move to stay current with AWS Lambda's evolving ecosystem. With improved performance, streamlined implementation, and minimal code changes, it's a win-win situation. So, why wait? Start your migration journey today and reap the benefits of a faster, more efficient Lambda experience. Happy coding!

Reference

  1. AWS compute blog
  2. Migrating AWS lambdas to Amazon linux 2
  3. Wkhtltopdf issue

Join us

Scalability, reliability, and maintainability are the three pillars that govern what we build at Halodoc Tech. We are actively looking for engineers at all levels, and if solving hard problems with challenging requirements is your forte, please reach out to us with your resume at careers.india@halodoc.com.

About Halodoc

Halodoc is the number 1 Healthcare application in Indonesia. Our mission is to simplify and bring quality healthcare across Indonesia, from Sabang to Merauke. We connect 20,000+ doctors with patients in need through our Tele-consultation service. We partner with 3500+ pharmacies in 100+ cities to bring medicine to your doorstep. We've also partnered with Indonesia's largest lab provider to provide lab home services, and to top it off we have recently launched a premium appointment service that partners with 500+ hospitals that allow patients to book a doctor appointment inside our application. We are extremely fortunate to be trusted by our investors, such as the Bill & Melinda Gates Foundation, Singtel, UOB Ventures, Allianz, GoJek, Astra, Temasek, and many more. We recently closed our Series D round and in total have raised around USD$100+ million for our mission. Our team works tirelessly to make sure that we create the best healthcare solution personalized for all of our patient's needs, and are continuously on a path to simplify healthcare for Indonesia.

Naveen GS

SDE SR 2 with Terraform expertise. Skilled in scalable infrastructure design, automation, and optimization. Committed to delivering high-quality solutions.