1

I'm trying to start a MediaConvert job with Ruby in AWS Lambda after a file has been uploaded to a bucket. The event kicks off fine, but I'm having trouble initiating the job.

I was trying to follow instructions from here to initiate the client: https://docs.aws.amazon.com/sdkforruby/api/Aws/MediaConvert/Client.html

And from here to kick off the job: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/MediaConvert/Client.html#create_job-instance_method

# Event to kick off the media conversion: file uploaded to a bucket
sourceS3Bucket = event['Records'][0]['s3']['bucket']['name']
sourceS3Key = event['Records'][0]['s3']['object']['key']
sourceS3 = 's3://'+ sourceS3Bucket + '/' + sourceS3Key
jobMetadata['input'] = sourceS3

# Loading the MediaConvert settings
json_from_file = File.read('job.json')
jobSettings = JSON.parse(json_from_file)

# Initiating a client
client = Aws::MediaConvert::Client.new(
  access_key_id: ENV['ACCESS_KEY_ID'],
  secret_access_key: ENV['SECRET_ACCESS_KEY']
)

# Kicking off a job
response = client.create_job({
  Role: ENV['MediaConvertRole'],
  UserMetadata: jobMetadata,
  Settings: jobSettings
})

I'm getting this error:

Critical exception from handler
{
  "errorMessage": "uninitialized constant Aws::MediaConvert",
  "errorType": "Function<NameError>",
  "stackTrace": [
    "/var/task/convert.rb:38:in `rescue in call'",
    "/var/task/convert.rb:6:in `call'"
  ]
}

I'm unsure why the function is failing, do you have any clues please?

Ivan Raszl
  • 330
  • 2
  • 12
  • 1
    `uninitialized constant Aws::MediaConvert` is telling you that the class you're calling has not been defined in the ruby script where you're calling it. You need to require it before you reach this point, normally at the top of your `.rb` file. – lacostenycoder Jun 24 '19 at 16:04
  • Yes. Thank you! I had require 'aws-sdk-s3', which I thought includes 'aws-sdk-mediaconvert', but it seems it doesn't. – Ivan Raszl Jun 25 '19 at 01:10

1 Answers1

2

You need to install aws-sdk-mediaconvert gem. Add this to Gemfile:

gem 'aws-sdk-mediaconvert'

and run

bundle

If you still getting this error require it at the top of your MediaConvert job:

require 'aws-sdk-mediaconvert'
Martin
  • 4,042
  • 2
  • 19
  • 29