Malay Shah
Malay Shah

Reputation: 452

Aws Lambda to List All Available Language Runtimes

I have a requirement where I want to make sure all individual Lambda functions are using the latest versions of the runtime.

Using CLI cmd: aws lambda get function I am able to get the runtime version of that particular lambda function but I want to make sure it is using the latest language version.

Going through the Aws Doc for Lambda https://docs.aws.amazon.com/cli/latest/reference/lambda am unable to find any API which can tell which all are available runtimes available and maybe from that list I can be able to determine which is the latest (maybe by checking the highest version number for that particular language).

So just wanted to know is there any AWS API that I failed to find or maybe some other way by which this can be achievable?

NOTE: I am not talking about the Lambda Function Versioning but about the language runtime version.
For, e.g., currently AWS lambda has Node.js 8.10 as the latest runtime. So if any Lambda function uses Node.js 6.10 as runtime, then I want to highlight that Lambda Function.

Upvotes: 8

Views: 2657

Answers (3)

TryTryAgain
TryTryAgain

Reputation: 7820

To add on to the accepted answer, within the botocore instead of searching for that sections I have used:

RuntimeVersionsURL="https://raw.githubusercontent.com/boto/botocore/develop/botocore/data/lambda/2015-03-31/service-2.json"

curl -s $RuntimeVersionsURL | jq -r '.shapes.Runtime.enum[]'

I've also gone the route of doing some HTML scraping using pup so as to be able to get a list of Supported vs. Unsupported/Deprecated runtime versions, using the following:

└❯ supportedRuntimeVersions=$(curl -s https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html \
    | pup '.table-container' | pup ':parent-of(:parent-of(:parent-of(:parent-of(:contains("Supported")))))' \
    | pup 'tbody code text{}' | sed '/^[[:space:]]*$/d' | tr -d ' ')

└❯ echo "$supportedRuntimeVersions" 
nodejs16.x
nodejs14.x
nodejs12.x
python3.9
python3.8
python3.7
java11
java8.al2
java8
dotnetcore3.1
dotnet6
dotnet5.0
go1.x
ruby2.7
provided.al2
provided

└❯ deprecatedRuntimeVersions=$(curl -s https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html \
    | pup '.table-container' | pup ':parent-of(:parent-of(:parent-of(:parent-of(:contains("Deprecated")))))' \
    | pup 'tbody code text{}' | sed '/^[[:space:]]*$/d'  | tr -d ' ')

└❯ echo "$deprecatedRuntimeVersions"
python3.6
python2.7
dotnetcore2.1
ruby2.5
nodejs10.x
nodejs8.10
nodejs4.3
nodejs6.10
dotnetcore1.0
dotnetcore2.0
nodejs4.3-edge
nodejs

Pretty ugly but it works well and helps provide info that should really be available via the API :/

EDIT, working version for two years later:

└❯ curl -s https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html | pup 'div.table-container' | pup 'div.table-container:first-of-type' | pup 'tbody code text{}' | sed '/^[[:space:]]*$/d' | tr -d ' '
nodejs20.x
nodejs18.x
python3.12
python3.11
python3.10
python3.9
java21
java17
java11
java8.al2
dotnet8
dotnet6
ruby3.3
ruby3.2
provided.al2023
provided.al2

└❯ curl -s https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html | pup 'div.table-container' | pup 'div.table-container:last-of-type' | pup 'tbody co
de text{}' | sed '/^[[:space:]]*$/d' | tr -d ' '
python3.8
nodejs16.x
dotnet7
java8
go1.x
provided
ruby2.7
nodejs14.x
python3.7
dotnetcore3.1
nodejs12.x
python3.6
dotnet5.0
dotnetcore2.1
nodejs10.x
ruby2.5
python2.7
nodejs8.10
nodejs4.3
nodejs4.3-edge
nodejs6.10
dotnetcore1.0
dotnetcore2.0
nodejs

Upvotes: 1

Paul Tobias
Paul Tobias

Reputation: 2203

Since this information is already present in botocore, as pointed out in the previous answers, I wanted to get it from botocore directly. Here is the python code to do that:

import botocore.session

session = botocore.session.get_session()
service_model = session.get_service_model("lambda")
runtime_enum = service_model.operation_model("CreateFunction").input_shape.members["Runtime"].enum
for runtime in runtime_enum:
    print(runtime)

For me the output is:

nodejs
nodejs4.3
nodejs6.10
nodejs8.10
nodejs10.x
nodejs12.x
nodejs14.x
nodejs16.x
java8
java8.al2
java11
python2.7
python3.6
python3.7
python3.8
python3.9
dotnetcore1.0
dotnetcore2.0
dotnetcore2.1
dotnetcore3.1
dotnet6
nodejs4.3-edge
go1.x
ruby2.5
ruby2.7
provided
provided.al2
nodejs18.x
python3.10
java17
ruby3.2
python3.11
nodejs20.x
provided.al2023
python3.12
java21

Upvotes: 0

John Rotenstein
John Rotenstein

Reputation: 269410

There is no official API call to obtain this information.

I found the following in the botocore source code:

"Runtime":{
  "type":"string",
  "enum":[
    "nodejs",
    "nodejs4.3",
    "nodejs6.10",
    "nodejs8.10",
    "java8",
    "python2.7",
    "python3.6",
    "python3.7",
    "dotnetcore1.0",
    "dotnetcore2.0",
    "dotnetcore2.1",
    "nodejs4.3-edge",
    "go1.x"
  ]
},

So, you could pull from that project on a regular basis to obtain a list of runtime versions.

Upvotes: 8

Related Questions