如何在 AWS Lambda 中使用 Ruby 启动媒体转换?

How to initiate a Media Conversion with Ruby in AWS Lambda?

在将文件上传到存储桶后,我正在尝试在 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'"
  ]
}

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

您需要安装 aws-sdk-mediaconvert gem。将此添加到 Gemfile:

gem 'aws-sdk-mediaconvert'

和运行

bundle

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

require 'aws-sdk-mediaconvert'