简体   繁体   中英

Injecting media to AWS MediaPackage from lambda function

I am trying to deliver hls media from a lambda function using nodejs to an AWS MediaPackage input endpoint. I am doing the following and seems to be pushing the media file chunks (ts files):

  const auth = 'Basic ' + Buffer.from(endpoints[0].Username + ':' + endpoints[0].Password).toString('base64');
  const options = {
    hostname: endpoints[0].Url.hostname,
    path: endpoints[0].Url.path,
    headers: {
      'Content-Type': 'application/json',
      'Authorization': auth,
      'Content-Length': Buffer.byteLength(data.Body)
    },
    body: data.Body // body of ts file
  };
  console.log(options);

  const res = await httpsPut(options); //Promise using https put to send the body in options

However, I don't see any logs in CloudWatch to the MediaPackage Channel

Is this the right way to send inject media to MediaPackage? I couldn't find any documentation

Thanks,

Well, I finally got it working following the documentation and doing a bit of try and error. In this MediaPackage documentation they mention that it only supports webdav auth so I ended up using a webdav module to handle the puts of files.

Assuming you are passing valid inputs, the working solution ended up looking like this:

/**
 * Helper PUT with Webdav and digest authentication to AWS MediaPackage
 * @param mediaPackageEndpoints
 * @param fileName
 * @param data
 */
const putToMediaPackage = async function(mediaPackageEndpoints, fileName, data) {
  const url = new URL(mediaPackageEndpoints[0].Url);
  const client = createClient(
    url.toString().replace('/channel', ''),
    {
      username: mediaPackageEndpoints[0].Username,
      password: mediaPackageEndpoints[0].Password,
      digest: true
    }
  );

  await client.putFileContents(fileName, data);
  return client;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM