1

在将文件上传到存储桶后,我正在尝试在 AWS Lambda 中使用 Ruby 启动 MediaConvert 作业。活动开始得很好,但我在开始工作时遇到了麻烦。

我试图按照此处的说明启动客户端:https ://docs.aws.amazon.com/sdkforruby/api/Aws/MediaConvert/Client.html

从这里开始工作: 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
})

我收到此错误:

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'"
  ]
}

我不确定为什么该功能会失败,请问您有任何线索吗?

4

1 回答 1

2

你需要安装aws-sdk-mediaconvertgem。将此添加到 Gemfile:

gem 'aws-sdk-mediaconvert'

并运行

bundle

如果您仍然收到此错误,请在您的 MediaConvert 作业的顶部使用它:

require 'aws-sdk-mediaconvert'
于 2019-06-24T17:10:25.147 回答