BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News AWS Lambda Now Supports Ruby 3.2 Runtime

AWS Lambda Now Supports Ruby 3.2 Runtime

This item in japanese

AWS continues to bring support for new versions of runtimes for AWS Lambda. Recently, the company announced the support of the Ruby 3.2 runtime.

Ruby 3.2 introduces various enhancements and performance upgrades, such as advancements in anonymous argument passing, the addition of 'endless' methods, improved regular expressions, the introduction of a new Data class, enhanced pattern-matching capabilities in Time and MatchData, and the inclusion of 'find pattern' support within pattern matching.

Praveen Koorse, senior solutions architect, AWS, writes in an AWS Compute blog post that Ruby 3.2 enhances the handling of anonymous arguments, simplifying and streamlining the utilization of keyword arguments in code and before this update, passing anonymous keyword arguments to a method involved using the delegation syntax (…) or employing Module#ruby2_keywords and delegating *args, &block. However, this approach was less intuitive and lacked clarity, particularly when dealing with multiple arguments.

If a method declaration now includes anonymous positional or keyword arguments, they can be passed to the next method as arguments. The same advantages of anonymous block forwarding apply to rest and keyword rest argument forwarding.

def keywords(**) # accept keyword arguments

  foo(**) # pass them to the next method

end

def positional(*) # accept positional arguments

  bar(*) # pass to the next method

end

def positional_keywords(*, **) # same as ...

  foobar(*, **)

end

Another example of improvement is that Ruby 3 introduced a new feature called "endless methods," which empowers developers to define methods with just one statement using the syntax def method() = statement. With this syntax, there is no need for an explicit end keyword, allowing methods to be defined as concise one-liners. This enhancement simplifies the creation of basic utility methods and contributes to writing cleaner code, enhancing code readability, and improving maintainability.

def dbg_args(a, b=1, c:, d: 6, &block) = puts("Args passed: #{[a, b, c, d, block.call]}")

dbg_args(0, c: 5) { 7 }

# Prints: Args passed: [0, 1, 5, 6, 7]



def square(x) = x**2

square(100)

# => 10000

To utilize Ruby 3.2 for deploying Lambda functions, developers can follow these steps: upload the code via the Lambda console and choose the Ruby 3.2 runtime. Alternatively, they can leverage the AWS CLI, AWS Serverless Application Model (AWS SAM), or AWS CloudFormation to deploy and administer serverless applications coded in Ruby 3.2. In addition, developers can also use the AWS-provided Ruby 3.2 base image to build and deploy Ruby 3.2 functions using a container image.

Tung Nguyen, founder of BoltOps Cloud Infrastructure Consultancy, tweeted:

Deployed a Jets v4 demo app on AWS Lambda Ruby 3.2. It was a success! No more need to use a Custom Runtime Lambda Layer.

In addition, a respondent to a Reddit thread about Ruby 3.2 support AWS Lambda stated:

Use containers and stop worrying what AWS supports. :)

With another one responding:

And manage my own runtime? Eh

Competitive Function as a Service (FaaS) offerings other than AWS Lambda, like Azure Functions, do not support any Ruby runtime version. Users can leverage Ruby (older runtimes) through a workaround for Azure Functions. On the other hand, Google Cloud Functions does support Ruby runtimes, including 3.2, which the company recommends using.

Lastly, Ruby 3.2 is Ruby's latest long-term support (LTS) release. AWS will automatically apply updates and security patches to the Ruby 3.2 managed runtime and the AWS-provided Ruby 3.2 base image as they become available.

More details of writing functions in Ruby 3.2 are available in the developer guide.

About the Author

Rate this Article

Adoption
Style

BT