I need to use mediaconvert to encode a video file, please use job template and supply IAM roles
TypeScriptTo achieve this, we'll create an AWS MediaConvert job using a job template and supply the necessary IAM roles. The IAM role will allow MediaConvert to access the input video file and write the output to an S3 bucket.
Here's a Pulumi program in TypeScript that accomplishes this:
import * as pulumi from "@pulumi/pulumi"; import * as aws from "@pulumi/aws"; // Create an S3 bucket for input and output const inputBucket = new aws.s3.Bucket("inputBucket"); const outputBucket = new aws.s3.Bucket("outputBucket"); // Create an IAM role for MediaConvert const mediaConvertRole = new aws.iam.Role("mediaConvertRole", { assumeRolePolicy: JSON.stringify({ Version: "2012-10-17", Statement: [ { Effect: "Allow", Principal: { Service: "mediaconvert.amazonaws.com", }, Action: "sts:AssumeRole", }, ], }), }); // Attach policies to the IAM role const mediaConvertPolicy = new aws.iam.RolePolicy("mediaConvertPolicy", { role: mediaConvertRole.id, policy: pulumi.output({ Version: "2012-10-17", Statement: [ { Effect: "Allow", Action: [ "s3:ListBucket", "s3:GetObject", "s3:PutObject", ], Resource: [ inputBucket.arn, `${inputBucket.arn}/*`, outputBucket.arn, `${outputBucket.arn}/*`, ], }, ], }).apply(JSON.stringify), }); // Create a MediaConvert job template const jobTemplate = new aws.mediaconvert.JobTemplate("jobTemplate", { settings: { Inputs: [{ FileInput: `s3://${inputBucket.bucket}/input-video.mp4`, }], OutputGroups: [{ Name: "File Group", OutputGroupSettings: { Type: "FILE_GROUP_SETTINGS", FileGroupSettings: { Destination: `s3://${outputBucket.bucket}/output/`, }, }, Outputs: [{ ContainerSettings: { Container: "MP4", }, VideoDescription: { CodecSettings: { Codec: "H_264", }, }, }], }], }, }); // Create a MediaConvert queue const queue = new aws.mediaconvert.Queue("queue", { description: "Default queue", }); // Create a MediaConvert job using the job template const mediaConvertJob = new aws.mediaconvert.Job("mediaConvertJob", { role: mediaConvertRole.arn, settings: jobTemplate.settings, queue: queue.arn, userMetadata: { "Job": "ExampleJob", }, }); export const inputBucketName = inputBucket.bucket; export const outputBucketName = outputBucket.bucket; export const mediaConvertJobId = mediaConvertJob.id;
This program does the following:
- Creates two S3 buckets: one for the input video and one for the output.
- Creates an IAM role for MediaConvert with the necessary permissions to read from the input bucket and write to the output bucket.
- Creates a MediaConvert job template with the encoding settings.
- Creates a MediaConvert queue.
- Creates a MediaConvert job using the job template and the IAM role.
Remember to upload your input video to the input bucket (
input-video.mp4
in this example) and adjust the file names and settings as needed.