Skip to content

Commit

Permalink
Merge pull request #1430 from alphagov/reuse-aws-client
Browse files Browse the repository at this point in the history
Reuse AWS client between S3 requests
  • Loading branch information
richardTowers authored Jul 2, 2024
2 parents 3860978 + 7e5b94a commit 342141a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/s3_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ def replication_status(asset)
end

def object_for(asset)
Aws::S3::Object.new(bucket_name: @bucket_name, key: asset.uuid)
Aws::S3::Object.new(bucket_name: @bucket_name, key: asset.uuid, client:)
end

def head_object_for(asset)
client.head_object(bucket: @bucket_name, key: asset.uuid)
end

def client
Aws::S3::Client.new
@client ||= Aws::S3::Client.new
end
end
2 changes: 1 addition & 1 deletion spec/lib/s3_storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
before do
allow(Aws::S3::Client).to receive(:new).and_return(s3_client)
allow(Aws::S3::Object).to receive(:new)
.with(s3_object_params).and_return(s3_object)
.with(hash_including(s3_object_params)).and_return(s3_object)
end

describe ".build" do
Expand Down

0 comments on commit 342141a

Please sign in to comment.