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?
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'