文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
GetJob
搭配 a AWS SDK 或 CLI 使用
下列程式碼範例示範如何使用 GetJob
。
- .NET
-
- AWS SDK for .NET
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 設定檔案位置、用戶端和包裝。
// MediaConvert role Amazon Resource Name (ARN). // For information on creating this role, see // https://docs.aws.amazon.com/mediaconvert/latest/ug/creating-the-iam-role-in-mediaconvert-configured.html. var mediaConvertRole = _configuration["mediaConvertRoleARN"]; // Include the file input and output locations in settings.json or settings.local.json. var fileInput = _configuration["fileInput"]; var fileOutput = _configuration["fileOutput"]; AmazonMediaConvertClient mcClient = new AmazonMediaConvertClient(); var wrapper = new MediaConvertWrapper(mcClient);
依任務 ID 取得任務。
Console.WriteLine(new string('-', 80)); Console.WriteLine($"Getting job information for Job ID {jobId}"); var job = await wrapper.GetJobById(jobId); Console.WriteLine($"Job {job.Id} created on {job.CreatedAt:d} has status {job.Status}."); Console.WriteLine(new string('-', 80));
/// <summary> /// Get the job information for a job by its ID. /// </summary> /// <param name="jobId">The ID of the job.</param> /// <returns>The Job object.</returns> public async Task<Job> GetJobById(string jobId) { var jobResponse = await _amazonMediaConvert.GetJobAsync( new GetJobRequest { Id = jobId }); return jobResponse.Job; }
-
如需 API 詳細資訊,請參閱 GetJob AWS SDK for .NET 參考中的 API。
-
- C++
-
- C++ 的 SDK
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 //! Retrieve the information for a specific completed transcoding job. /*! \param jobID: A job ID. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::MediaConvert::getJob(const Aws::String &jobID, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::MediaConvert::MediaConvertClient client(clientConfiguration); Aws::MediaConvert::Model::GetJobRequest request; request.SetId(jobID); const Aws::MediaConvert::Model::GetJobOutcome outcome = client.GetJob( request); if (outcome.IsSuccess()) { std::cout << outcome.GetResult().GetJob().Jsonize().View().WriteReadable() << std::endl; } else { std::cerr << "DescribeEndpoints error - " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
-
如需 API 詳細資訊,請參閱 GetJob AWS SDK for C++ 參考中的 API。
-
- CLI
-
- AWS CLI
-
若要取得特定任務的詳細資訊
下列範例會請求 ID 為 的任務資訊
1234567890987-1ab2c3
,在此範例中, ID 為 結束。aws mediaconvert get-job \ --endpoint-url
https://abcd1234.mediaconvert.region-name-1.amazonaws.com
\ --regionregion-name-1
\ --id1234567890987-1ab2c3
若要取得您的帳戶特定端點,請使用
describe-endpoints
,或傳送不含端點的命令。服務會傳回錯誤和端點。如果您的請求成功,服務會傳回包含任務資訊的 JSON 檔案,包括任務設定、任何傳回的錯誤,以及其他任務資料,如下所示:
{ "Job": { "Status": "ERROR", "Queue": "arn:aws:mediaconvert:region-name-1:012345678998:queues/Queue1", "Settings": { ...<truncated for brevity>... }, "ErrorMessage": "Unable to open input file [s3://my-input-bucket/file-name.mp4]: [Failed probe/open: [Failed to read data: AssumeRole failed]]", "ErrorCode": 1434, "Role": "arn:aws:iam::012345678998:role/MediaConvertServiceRole", "Arn": "arn:aws:mediaconvert:us-west-1:012345678998:jobs/1234567890987-1ab2c3", "UserMetadata": {}, "Timing": { "FinishTime": 1517442131, "SubmitTime": 1517442103, "StartTime": 1517442104 }, "Id": "1234567890987-1ab2c3", "CreatedAt": 1517442103 } }
如需詳細資訊,請參閱 AWS Elemental MediaConvert 使用者指南中的使用 ElementalWord 任務。 AWS MediaConvert
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 GetJob
。
-
- Java
-
- Java 2.x 的 SDK
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.mediaconvert.model.DescribeEndpointsResponse; import software.amazon.awssdk.services.mediaconvert.model.GetJobRequest; import software.amazon.awssdk.services.mediaconvert.model.DescribeEndpointsRequest; import software.amazon.awssdk.services.mediaconvert.model.GetJobResponse; import software.amazon.awssdk.services.mediaconvert.model.MediaConvertException; import software.amazon.awssdk.services.mediaconvert.MediaConvertClient; import java.net.URI; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class GetJob { public static void main(String[] args) { final String usage = "\n" + " <jobId> \n\n" + "Where:\n" + " jobId - The job id value.\n\n"; if (args.length != 1) { System.out.println(usage); System.exit(1); } String jobId = args[0]; Region region = Region.US_WEST_2; MediaConvertClient mc = MediaConvertClient.builder() .region(region) .build(); getSpecificJob(mc, jobId); mc.close(); } public static void getSpecificJob(MediaConvertClient mc, String jobId) { try { DescribeEndpointsResponse res = mc.describeEndpoints(DescribeEndpointsRequest.builder() .maxResults(20) .build()); if (res.endpoints().size() <= 0) { System.out.println("Cannot find MediaConvert service endpoint URL!"); System.exit(1); } String endpointURL = res.endpoints().get(0).url(); MediaConvertClient emc = MediaConvertClient.builder() .region(Region.US_WEST_2) .endpointOverride(URI.create(endpointURL)) .build(); GetJobRequest jobRequest = GetJobRequest.builder() .id(jobId) .build(); GetJobResponse response = emc.getJob(jobRequest); System.out.println("The ARN of the job is " + response.job().arn()); } catch (MediaConvertException e) { System.out.println(e.toString()); System.exit(0); } } }
-
如需 API 詳細資訊,請參閱 GetJob AWS SDK for Java 2.x 參考中的 API。
-
- Kotlin
-
- Kotlin 的 SDK
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 suspend fun getSpecificJob( mcClient: MediaConvertClient, jobId: String?, ) { val describeEndpoints = DescribeEndpointsRequest { maxResults = 20 } val res = mcClient.describeEndpoints(describeEndpoints) if (res.endpoints?.size!! <= 0) { println("Cannot find MediaConvert service endpoint URL!") exitProcess(0) } val endpointURL = res.endpoints!!.get(0).url!! val mediaConvert = MediaConvertClient.fromEnvironment { region = "us-west-2" endpointProvider = MediaConvertEndpointProvider { Endpoint(endpointURL) } } val jobRequest = GetJobRequest { id = jobId } val response: GetJobResponse = mediaConvert.getJob(jobRequest) println("The ARN of the job is ${response.job?.arn}.") }
-
如需 API 詳細資訊,請參閱 GetJob
AWS for Kotlin SDK 參考中的 API。
-