Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ Aws.config[:credentials] = Aws::Credentials.new(
For more information on how to configure credentials, see the developer guide
for [configuring AWS SDK for Ruby](https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html).

## Eager loading

The SDK normally loads service constants when your application first uses them.
Applications that want to load SDK constants during startup can opt in after
requiring their service gems:

```ruby
require 'aws-sdk-s3'
require 'aws-sdk-sqs'

Aws.eager_load!
```

`Aws.eager_load!` loads SDK constants from gems that were required before the
call. It does not make any AWS service requests. Requiring only the service
gems your application uses limits the code loaded into memory.

## API Clients

Construct a service client to make API calls. Each client provides a 1-to-1
Expand Down
2 changes: 2 additions & 0 deletions gems/aws-sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Feature - Add `Aws.eager_load!` to eagerly resolve constants registered by loaded AWS SDK gems.

3.271.1 (2026-11-20)
------------------

Expand Down
29 changes: 29 additions & 0 deletions gems/aws-sdk-core/lib/aws-sdk-core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,35 @@ def empty_connection_pools!
end
end

# Eager loads SDK constants from gems that have already been required.
#
# Call this method during application startup, after requiring the service
# gems your application uses:
#
# require 'aws-sdk-s3'
# require 'aws-sdk-sqs'
#
# Aws.eager_load!
#
# Service gems required after this call are not eager loaded. This method
# loads Ruby code but does not make any AWS service requests. Eager loading
# can increase memory usage, so applications should require only the
# service gems they use.
#
# @return [void]
def eager_load!
Aws.constants.each do |name|
namespace = Aws.const_get(name)
next unless namespace.is_a?(Module)

namespace.constants.each do |constant|
namespace.const_get(constant)
end
end

nil
end

# @api private
def eager_autoload!(*args)
msg = 'Aws.eager_autoload is no longer needed, usage of '\
Expand Down
2 changes: 2 additions & 0 deletions gems/aws-sdk-core/sig/aws-sdk-core.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ module Aws
def self.config=: (Hash[Symbol, untyped] config) -> Hash[Symbol, untyped]

def self.use_bundled_cert!: () -> String

def self.eager_load!: () -> nil
end
15 changes: 15 additions & 0 deletions gems/aws-sdk-core/spec/aws_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,19 @@ module Aws
expect(conn_pool.size).to eq(0)
end
end

describe '.eager_load!' do
it 'resolves constants under loaded SDK namespaces' do
service = Module.new
stub_const('Aws::TestService', service)

allow(Aws).to receive(:constants).and_return([:TestService])
allow(service).to receive(:constants).and_return([:Client])
expect(Aws).to receive(:const_get)
.with(:TestService).and_call_original
expect(service).to receive(:const_get).with(:Client)

expect(Aws.eager_load!).to be_nil
end
end
end