Reputation: 295
In my Rails application, I need to use AWS Transcribe service. But, when I tried to create the AWS client from inside ActiveJob, the Sidekiq log always gives me NameError: uninitialized constant Aws::TranscribeService
. But, when I tried to create the client directly from the Rails console, it doesn't complain. Here is my code.
/app/job/transcribe_audio_job.rb
class TranscribeAudioJob < ApplicationJob
queue_as :default
def perform(job_id)
job = TranscriptionJob.find(job_id)
# This line always show: NameError: uninitialized constant Aws::TranscribeService
client = Aws::TranscribeService::Client.new(
region: 'eu-west-1'
)
p client
end
end
Gemfile
# AWS SDK
gem 'aws-sdk-rails', '~> 3'
gem 'aws-sdk-transcribeservice', '~> 1.50'
That code above is working if I try directly in the Rails console.
client = Aws::TranscribeService::Client.new(
region: 'eu-west-1'
)
# <Aws::TranscribeService::Client> <- The result in the Rails console
How's the correct way to use the AWS SDK from ActiveJob? Thanks for your help.
Upvotes: 0
Views: 122
Reputation: 295
The solution from Arieljuod in the comment works. Here's the complete code:
/app/job/transcribe_audio_job.rb
require 'aws-sdk-transcribeservice'
class TranscribeAudioJob < ApplicationJob
queue_as :default
def perform(job_id)
job = TranscriptionJob.find(job_id)
client = Aws::TranscribeService::Client.new(
region: 'eu-west-1'
)
p client
end
end
Upvotes: 0