📝

Lambda の各ランタイムにデフォルトでインストールされているライブラリを確認する方法

に公開1

以下のランタイムで確認してみました。

  • Node.js 22.x
  • Python 3.13
  • Ruby 3.4
  • Java 21
  • .NET 8 (C#)

Node.js 22.x

exports.handler = async (event) => {
  const builtinModules = require('module').builtinModules;

  [...builtinModules].sort().forEach(module => {
    console.log(module);
  });
実行結果
_http_agent
_http_client
_http_common
_http_incoming
_http_outgoing
_http_server
_stream_duplex
_stream_passthrough
_stream_readable
_stream_transform
_stream_wrap
_stream_writable
_tls_common
_tls_wrap
assert
assert/strict
async_hooks
buffer
child_process
cluster
console
constants
crypto
dgram
diagnostics_channel
dns
dns/promises
domain
events
fs
fs/promises
http
http2
https
inspector
inspector/promises
module
net
os
path
path/posix
path/win32
perf_hooks
process
punycode
querystring
readline
readline/promises
repl
stream
stream/consumers
stream/promises
stream/web
string_decoder
sys
timers
timers/promises
tls
trace_events
tty
url
util
util/types
v8
vm
wasi
worker_threads
zlib

Python 3.13

import sys
import pkgutil

def lambda_handler(event, context):
    
    modules = []
    for importer, modname, ispkg in pkgutil.iter_modules():
        modules.append(modname)

    for module in sorted(modules):
        print(module)
実行結果
future
hello
phello
_aix_support
_android_support
_apple_support
_asyncio
_bisect
_blake2
_bz2
_codecs_cn
_codecs_hk
_codecs_iso2022
_codecs_jp
_codecs_kr
_codecs_tw
_collections_abc
_colorize
_compat_pickle
_compression
_contextvars
_csv
_ctypes
_ctypes_test
_curses
_curses_panel
_datetime
_dbm
_decimal
_elementtree
_gdbm
_hashlib
_heapq
_interpchannels
_interpqueues
_interpreters
_ios_support
_json
_lsprof
_lzma
_markupbase
_md5
_multibytecodec
_multiprocessing
_opcode
_opcode_metadata
_osx_support
_pickle
_posixshmem
_posixsubprocess
_py_abc
_pydatetime
_pydecimal
_pyio
_pylong
_pyrepl
_queue
_random
_sha1
_sha2
_sha3
_sitebuiltins
_socket
_sqlite3
_ssl
_statistics
_strptime
_struct
_sysconfigdata__linux_x86_64-linux-gnu
_testbuffer
_testcapi
_testclinic
_testclinic_limited
_testexternalinspection
_testimportmultiple
_testinternalcapi
_testlimitedcapi
_testmultiphase
_testsinglephase
_threading_local
_weakrefset
_xxtestfuzz
_zoneinfo
abc
antigravity
argparse
array
ast
asyncio
awslambdaric
base64
bdb
binascii
bisect
bootstrap
boto3
botocore
bz2
cProfile
calendar
cmath
cmd
code
codecs
codeop
collections
colorsys
compileall
concurrent
configparser
contextlib
contextvars
copy
copyreg
csv
ctypes
curses
dataclasses
datetime
dateutil
dbm
decimal
difflib
dis
doctest
email
encodings
ensurepip
enum
fcntl
filecmp
fileinput
fnmatch
fractions
ftplib
functools
genericpath
getopt
getpass
gettext
glob
graphlib
grp
gzip
hashlib
heapq
hmac
html
http
idlelib
imaplib
importlib
inspect
io
ipaddress
jmespath
json
keyword
lambda_function
linecache
locale
logging
lzma
mailbox
math
mimetypes
mmap
modulefinder
multiprocessing
netrc
ntpath
nturl2path
numbers
opcode
operator
optparse
os
pathlib
pdb
pickle
pickletools
pip
pkgutil
platform
plistlib
poplib
posixpath
pprint
profile
pstats
pty
py_compile
pyclbr
pydoc
pydoc_data
pyexpat
queue
quopri
random
re
readline
reprlib
resource
rlcompleter
runpy
runtime_client
s3transfer
sched
secrets
select
selectors
shelve
shlex
shutil
signal
simplejson
site
six
smtplib
snapshot_restore_py
socket
socketserver
sqlite3
sre_compile
sre_constants
sre_parse
ssl
stat
statistics
string
stringprep
struct
subprocess
symtable
sysconfig
syslog
tabnanny
tarfile
tempfile
termios
test
textwrap
this
threading
timeit
tkinter
token
tokenize
tomllib
trace
traceback
tracemalloc
tty
turtle
turtledemo
types
typing
unicodedata
unittest
urllib
urllib3
uuid
venv
warnings
wave
weakref
webbrowser
wsgiref
xml
xmlrpc
xxlimited
xxlimited_35
xxsubtype
zipapp
zipfile
zipimport
zlib
zoneinfo

Ruby 3.4

def lambda_handler(event:, context:)

    gems = Gem::Specification.default_stubs.map(&:name)

    gems.sort.each do |gem|
        puts gem
    end
end
実行結果
benchmark
bundler
cgi
date
delegate
did_you_mean
digest
english
erb
error_highlight
etc
fcntl
fiddle
fileutils
find
forwardable
io-console
io-nonblock
io-wait
ipaddr
irb
json
logger
net-http
net-protocol
open-uri
open3
openssl
optparse
ostruct
pathname
pp
prettyprint
prism
pstore
psych
rdoc
readline
reline
resolv
ruby2_keywords
securerandom
set
shellwords
singleton
stringio
strscan
syntax_suggest
tempfile
time
timeout
tmpdir
tsort
un
uri
weakref
yaml
zlib

Java 21

CloudShell から Java の Lambda 関数を作成してみた

package com.example;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;

public class HelloWorld implements RequestHandler<Object, String> {
    @Override
    public String handleRequest(Object input, Context context) {

        ModuleLayer.boot().modules().stream()
            .map(Module::getName)
            .sorted()
            .forEach(System.out::println);
        
        return "Hello from Lambda!";
    }
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>lambda-hello-world</artifactId>
  <packaging>jar</packaging>
  <version>1.0</version>
  <name>lambda-hello-world</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.amazonaws</groupId>
      <artifactId>aws-lambda-java-core</artifactId>
      <version>1.2.0</version>
    </dependency>
    <dependency>
      <groupId>com.amazonaws</groupId>
      <artifactId>aws-java-sdk-core</artifactId>
      <version>1.12.568</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.1</version>
        <configuration>
          <createDependencyReducedPom>false</createDependencyReducedPom>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
実行結果
java.base
java.compiler
java.datatransfer
java.desktop
java.instrument
java.logging
java.management
java.management.rmi
java.naming
java.net.http
java.prefs
java.rmi
java.scripting
java.security.jgss
java.security.sasl
java.smartcardio
java.sql
java.sql.rowset
java.transaction.xa
java.xml
java.xml.crypto
jdk.accessibility
jdk.attach
jdk.charsets
jdk.compiler
jdk.crypto.cryptoki
jdk.crypto.ec
jdk.dynalink
jdk.editpad
jdk.httpserver
jdk.internal.ed
jdk.internal.jvmstat
jdk.internal.le
jdk.internal.opt
jdk.jartool
jdk.javadoc
jdk.jconsole
jdk.jdeps
jdk.jdi
jdk.jdwp.agent
jdk.jfr
jdk.jlink
jdk.jpackage
jdk.jshell
jdk.jsobject
jdk.jstatd
jdk.localedata
jdk.management
jdk.management.agent
jdk.management.jfr
jdk.naming.dns
jdk.naming.rmi
jdk.net
jdk.nio.mapmode
jdk.random
jdk.sctp
jdk.security.auth
jdk.security.jgss
jdk.unsupported
jdk.unsupported.desktop
jdk.xml.dom
jdk.zipfs

.NET 8 (C#)

AWS CloudShell から .NET の Lambda 関数をデプロイしてみた

using Amazon.Lambda.Core;
using System;
using System.Reflection;
using System.Linq;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace HelloWorldLambda;

public class Function
{
    public string FunctionHandler(string input, ILambdaContext context)
    {
        var assemblies = AppDomain.CurrentDomain.GetAssemblies()
            .Select(a => a.GetName().Name)
            .OrderBy(name => name);
            
        foreach (var assembly in assemblies)
        {
            Console.WriteLine(assembly);
        }
        
        return "Hello from Lambda!";
    }
}
実行結果
Amazon.Lambda.Core
Amazon.Lambda.RuntimeSupport
Amazon.Lambda.Serialization.SystemTextJson
Anonymously Hosted DynamicMethods Assembly
HelloWorldLambda
Microsoft.Win32.Primitives
System.Collections
System.Collections.Concurrent
System.Console
System.Diagnostics.DiagnosticSource
System.Diagnostics.Tracing
System.Linq
System.Linq.Expressions
System.Memory
System.Net.Http
System.Net.NameResolution
System.Net.Primitives
System.Net.Security
System.Net.Sockets
System.Numerics.Vectors
System.Private.CoreLib
System.Private.Uri
System.Reflection.Emit.ILGeneration
System.Reflection.Emit.Lightweight
System.Reflection.Primitives
System.Runtime
System.Runtime.InteropServices
System.Runtime.Intrinsics
System.Runtime.Loader
System.Security.Cryptography
System.Text.Encoding.Extensions
System.Text.Encodings.Web
System.Text.Json
System.Threading
System.Threading.Thread
System.Threading.ThreadPool

まとめ

今回は Lambda の各ランタイムにデフォルトでインストールされているライブラリを確認する方法を紹介しました。
どなたかの参考になれば幸いです。

Discussion

MizMiz

Lambdaのランタイムとしてインストールされているライブラリとしては、ビルトインモジュールの他にAWS SDKのパッケージも存在します。

Node.js 22.xのLambda上で実際に確認してみますと、以下のように出力されます。

import fs from 'fs';

export const handler = async () => {
  console.log(fs.readdirSync('/var/runtime/node_modules'));
  console.log(fs.readdirSync('/var/runtime/node_modules/@aws-sdk/'));
};
実行結果
2025-09-18T13:30:52.575Z	902b8d85-025c-41f0-80e1-7748cb28ef2a	INFO	[ '@aws-sdk' ]
2025-09-18T13:30:52.597Z	902b8d85-025c-41f0-80e1-7748cb28ef2a	INFO	[
  'abort-controller',
  'body-checksum-node',
  'chunked-stream-reader-node',
  'client-accessanalyzer',
  'client-account',
  'client-acm',
  'client-acm-pca',
  'client-aiops',
  'client-amp',
  'client-amplify',
  'client-amplifybackend',
  'client-amplifyuibuilder',
  'client-api-gateway',
  'client-apigatewaymanagementapi',
  'client-apigatewayv2',
  'client-app-mesh',
  'client-appconfig',
  'client-appconfigdata',
  'client-appfabric',
  'client-appflow',
  'client-appintegrations',
  'client-application-auto-scaling',
  'client-application-discovery-service',
  'client-application-insights',
  'client-application-signals',
  'client-applicationcostprofiler',
  'client-apprunner',
  'client-appstream',
  'client-appsync',
  'client-apptest',
  'client-arc-zonal-shift',
  'client-artifact',
  'client-athena',
  'client-auditmanager',
  'client-auto-scaling',
  'client-auto-scaling-plans',
  'client-b2bi',
  'client-backup',
  'client-backup-gateway',
  'client-backupsearch',
  'client-batch',
  'client-bcm-data-exports',
  'client-bcm-pricing-calculator',
  'client-bedrock',
  'client-bedrock-agent',
  'client-bedrock-agent-runtime',
  'client-bedrock-agentcore',
  'client-bedrock-agentcore-control',
  'client-bedrock-data-automation',
  'client-bedrock-data-automation-runtime',
  'client-bedrock-runtime',
  'client-billing',
  'client-billingconductor',
  'client-braket',
  'client-budgets',
  'client-chatbot',
  'client-chime',
  'client-chime-sdk-identity',
  'client-chime-sdk-media-pipelines',
  'client-chime-sdk-meetings',
  'client-chime-sdk-messaging',
  'client-chime-sdk-voice',
  'client-cleanrooms',
  'client-cleanroomsml',
  'client-cloud9',
  'client-cloudcontrol',
  'client-clouddirectory',
  'client-cloudformation',
  'client-cloudfront',
  'client-cloudfront-keyvaluestore',
  'client-cloudhsm',
  'client-cloudhsm-v2',
  'client-cloudsearch',
  'client-cloudsearch-domain',
  'client-cloudtrail',
  'client-cloudtrail-data',
  'client-cloudwatch',
  'client-cloudwatch-events',
  'client-cloudwatch-logs',
  'client-codeartifact',
  'client-codebuild',
  'client-codecatalyst',
  'client-codecommit',
  'client-codeconnections',
  'client-codedeploy',
  'client-codeguru-reviewer',
  'client-codeguru-security',
  'client-codeguruprofiler',
  'client-codepipeline',
  'client-codestar-connections',
  'client-codestar-notifications',
  'client-cognito-identity',
  'client-cognito-identity-provider',
  'client-cognito-sync',
  'client-comprehend',
  'client-comprehendmedical',
  'client-compute-optimizer',
  'client-config-service',
  'client-connect',
  'client-connect-contact-lens',
  ... 431 more items
]