如何创建PHP函数以向AWS创建此JSON请求(创建作业)

There is a new service on AWS called Elastic Transcoder. I know some PHP, but I have bitten off more than I can chew on this one...

How would I create a simple PHP function that will take my variables and create a JSON request (properly formatted of course) and create a job on the AWS. Here is the syntax that AWS supplies:

NOTE: I have a form already created that will be able to supply all the required fields.

To create a job, send a POST request to the

/2012-09-25/jobs

resource.

This is the syntax:

POST /2012-09-25/jobs HTTP/1.1
Content-Type: application/json; charset=UTF-8
Accept: */*
Host: elastictranscoder.Elastic Transcoder endpoint.amazonaws.com:443
x-amz-date: Mon, 14 Jan 2013 17:49:52 GMT
Authorization: AWS4-HMAC-SHA256 
           Credential=AccessKeyID/request-date/Elastic Transcoder endpoint/ets/aws4_request,
           SignedHeaders=host;x-amz-date;x-amz-target,
           Signature=calculated-signature
Content-Length: number of characters in the JSON string
{
"Input":{
  "Key":"name of the file to transcode",
  "FrameRate":"auto"|"10"|"15"|"23.97"|"24"|"25"|"29.97"|"30"|"60",
  "Resolution":"auto"|"width in pixelsxheight in pixels",
  "AspectRatio":"auto"|"1:1"|"4:3"|"3:2"|"16:9",
  "Interlaced":"auto"|"true"|"false",
  "Container":"auto"|"3gp"|"asf"|"avi"|"divx"|"flv"|"mkv"|"mov"|"mp4"|
     "mpeg"|"mpeg-ps"|"mpeg-ts"|"mxf"|"ogg"|"vob"|"wav"|"webm"
},
"Output":{
  "Key":"name of the transcoded file",
  "ThumbnailPattern":""|"pattern",
  "Rotate":"auto"|"0"|"90"|"180"|"270",
  "PresetId":"preset to use for the job"
},
"PipelineId":"pipeline to add the job to"
}

The parts of the above code that need to be supplied are show in italics in this original posting of the syntax:

http://docs.aws.amazon.com/elastictranscoder/latest/developerguide/create-job.html#create-job-examples

The AWS SDK for PHP includes support for Amazon Elastic Transcoder. Is there a reason that you don't want to use that? Here is a link to the PHP SDK documentation.

I recommend using a library, especially if you're feeling in over your head.

If you don't want to install the SDK or would prefer to avoid the overhead of a larger package, here is a standalone PHP class for working with Elastic Transcoder:

https://github.com/LPology/ElasticTranscoderPHP

To create a new transcoding job (with default settings):

$pipelineId = 'pipelineId';
$input = array('Key' => 'inputFile');
$output = array(
  'Key' => 'outputFile.mp4',
  'PresetId' => 'presetId'
);

AWS_ET::setAuth($awsAccessKey, $awsSecretKey);
$result = AWS_ET::createJob($input, array($output), $pipelineId);