Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK Eager loading #140

Merged
merged 3 commits into from
Sep 27, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Feature - Add SDK eager loading to optimize load times. See: https://github.com/aws/aws-sdk-ruby/pull/3105.

4.0.3 (2024-07-31)
------------------

Expand Down
19 changes: 19 additions & 0 deletions lib/aws/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ class Railtie < ::Rails::Railtie
Aws::Rails.add_sqsd_middleware(app)
end

initializer 'aws-sdk-rails.sdk_eager_load' do
config.before_eager_load do
config.eager_load_namespaces << Aws
end

Aws.define_singleton_method(:eager_load!) do
Aws.constants.each do |c|
m = Aws.const_get(c)
next unless m.is_a?(Module)

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

rake_tasks do
load 'tasks/dynamo_db/session_store.rake'
load 'tasks/aws_record/migrate.rake'
Expand Down Expand Up @@ -66,6 +83,8 @@ def self.use_rails_encrypted_credentials
# name of: put_object.S3.aws
def self.instrument_sdk_operations
Aws.constants.each do |c|
next if Aws.autoload?(c)

m = Aws.const_get(c)
if m.is_a?(Module) && m.const_defined?(:Client) &&
m.const_get(:Client).superclass == Seahorse::Client::Base
Expand Down
5 changes: 5 additions & 0 deletions spec/aws/rails/railtie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ module Rails
expect(Aws.config[:logger]).to eq ::Rails.logger
end

it 'sets up eager loading for sdk services' do
expect(Aws.methods).to include(:eager_load!)
expect(::Rails.application.config.eager_load_namespaces).to include(Aws)
end

describe '.use_rails_encrypted_credentials' do
let(:rails_creds) { ::Rails.application.credentials.aws }
it 'sets aws credentials' do
Expand Down
1 change: 1 addition & 0 deletions spec/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
config.action_mailbox.ingress = :ses
config.action_mailbox.ses.subscribed_topic = 'arn:aws:sns:eu-west-1:012345678910:example-topic'
config.action_dispatch.show_exceptions = :none
config.eager_load = true
end