AWS Compute Blog

Python 3.8 runtime now available in AWS Lambda

You can now develop your AWS Lambda functions using the Python 3.8 runtime. Start using this runtime today by specifying a runtime parameter value of python3.8 when creating or updating Lambda functions.

New Python runtime features

Python 3.8 is a stable release and brings several new features, including assignment expressions, positional-only arguments, and vectorcall.

Assignment expressions

Assignment expressions provide a way to assign values to variables within expressions using the new notation NAME := expr. This is informally known as the “walrus operator,” as it looks like the eyes and tusks of a walrus on its side.

Before:

>>> walrus = True
print(walrus)
True

After:

>>> print(walrus := True)
True

Previously, assignment was only available in statement form. With Python 3.8, it is available in list comprehensions and other expression contexts.

For examples, usage, and limitations, see PEP-572.

Positional-only arguments

Positional-only parameters give more control to library authors by introducing a new function parameter syntax `/` to indicate that some function parameters must be specified positionally and cannot be used as keyword arguments.

When describing APIs, they can be used to better express the intended usage and allow the API to evolve in a safe, backward-compatible way. They also make the Python language more consistent with existing documentation and the behavior of various “builtin” and standard library functions.

For a full specification, including syntax and examples, see PEP-570 and PEP-457.

f-strings support

An f-string is a formatted string literal to enclose variables, and even expressions, inside curly braces. An F-string is evaluated at runtime and included in the string, recognized by the leading f:

>>> city = "London"
>>> f"Living in {city} is amazing"
'Living in London is amazing'

Python 3.8 adds the ability to use assignment expressions inside f-strings which are evaluated from left-to-right.

>>> import math
>>> radius = 3.8

>>> f"With a diameter of {( diameter := 2 * radius)}, the circumference is {math.pi * diameter:.2f}"
' With a diameter of 7.6 the circumference is 23.88'

Vectorcall

Vectorcall is a new protocol and calling convention based on the “fastcall” convention, which was previously used internally by CPython. The new features can be used by any user-defined extension class. Vectorcall generalizes the calling convention used internally for Python and builtin functions so that all calls can benefit from better performance. It is designed to remove the overhead of temporary object creation and multiple indirections.

For additional information on vectorcall, see PEP-590.

Amazon Linux 2

Python 3.8, like Node.js 10 and 12, and Java 11, is based on an Amazon Linux 2 execution environment. Amazon Linux 2 provides a secure, stable, and high-performance execution environment to develop and run cloud and enterprise applications.

Next steps

Get started building with Python 3.8 today by specifying a runtime parameter value of python3.8 when creating or updating your Lambda functions.

Enjoy, go build with Python 3.8!