AWS Lambda Adopts Python 3.11
Written by Nikos Vaggalis   
Thursday, 21 September 2023

Recently AWS Lamda switched from Python runtime 3.10 to 3.11, promising a lot of improvement. In which parts?

Back in May we had a look at Amazon's adoption of the Python 3.10 runtime intened to take advantage of the performance improvements that version introduced, in both managed runtimes and container images. Python 3.10 enabled the use of the following enhancements when building lambda functions:

  • Structural Pattern Matching
  • Parenthesized context managers
  • Better error messages
  • New Type Union Operator
  • Parameter Specification Variables
  • User-Defined Type Guards
  • Stricter Zipping
  • Automatic Text Encoding
  • Asynchronous Iteration

and provided the performance enhancements of that version, like the faster PEP 590 vectorcall calling convention which allows for quicker and more efficient Python function calls, particularly those that take multiple arguments.

The new 3.11 runtime brings additional improvements. Python 3.11 contains significant performance enhancements over Python 3.10 - like reduced startup time and streamlined stack frames, while the CPython specialization adaptive interpreter helps many workloads using Python 3.11 run faster and cheaper.

pi311aws

Talking about CPython, the related optimizations introduced in Python 3.11 makes operation an average of 25% faster than those of Python 3. 10. Along with it, Python 3.11 also provides performance-related features in the Core including:

  • String formatting with printf-style% codes is now as fast as f-string expressions.
  • Integer division is around 20% faster on x86-64 for certain scenarios.
  • Operations like sum() and list resizing have seen notable speed enhancements.
  • Dictionaries save memory by not storing hash values when keys are Unicode objects.

and more.

Of course, devs can also now take advantage of the language features added in Python 3.11:

  • Variadic generics
  • Marking individual TypedDict items as required or not-required
  • Self type
  • Arbitrary literal string type
  • Data class transforms


It is recommended that you upgrade your 3.10 based container images to the newest version by changing the Python base image version by modifying the FROM statement in the Dockerfile:

FROM public.ecr.aws/lambda/python:3.11
# Copy function code
COPY lambda_handler.py ${LAMBDA_TASK_ROOT}

or better yet get a hold of AWS's certified container images which are regularly updated with security patches and other updates and come optimized by changing the components or dependencies included in them.

 

 

More Information

Python 3.11 runtime now available in AWS Lambda

Related Articles

AWS Lambda Adopts Python 3.10

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Use Javascriptmas To Hone Your Webdev Skills
08/12/2024

Every day until December 24th MDN, in partnership with Scrimba, is releasing a daily challenge, which as the name suggests requires you to practice your JavaScript skills. Each solution you submi [ ... ]



Meta Releases OpenSource Podcast Generating Tool
28/11/2024

Meta has released an open source project that can be used to automatically convert a PDF file into a podcast. Meta says Notebook Llama can be considered an open-source version of Google's NotebookLM.

 [ ... ]


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Thursday, 21 September 2023 )