将 PutJobTagging 和 Amazon SDK 搭配使用
以下代码示例演示如何使用 PutJobTagging。
操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:
- Java
-
- 适用于 Java 的 SDK 2.x
-
注意
查看 GitHub,了解更多信息。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 /** * Asynchronously adds tags to a job in the system. * * @param jobId the ID of the job to add tags to * @param accountId the account ID associated with the job * @return a CompletableFuture that completes when the tagging operation is finished */ public CompletableFuture<Void> putJobTaggingAsync(String jobId, String accountId) { S3Tag departmentTag = S3Tag.builder() .key("department") .value("Marketing") .build(); S3Tag fiscalYearTag = S3Tag.builder() .key("FiscalYear") .value("2020") .build(); PutJobTaggingRequest putJobTaggingRequest = PutJobTaggingRequest.builder() .jobId(jobId) .accountId(accountId) .tags(departmentTag, fiscalYearTag) .build(); return asyncClient.putJobTagging(putJobTaggingRequest) .thenRun(() -> { System.out.println("Additional Tags were added to job " + jobId); }) .exceptionally(ex -> { System.err.println("Failed to add tags to job: " + ex.getMessage()); throw new RuntimeException(ex); // Propagate the exception }); }-
有关 API 详细信息,请参阅《Amazon SDK for Java 2.x API Reference》中的 PutJobTagging。
-
- Python
-
- 适用于 Python 的 SDK(Boto3)
-
注意
查看 GitHub,了解更多信息。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 def put_job_tags(self, job_id: str, account_id: str) -> None: """ Add tags to a batch job. Args: job_id (str): ID of the batch job account_id (str): AWS account ID """ try: self.s3control_client.put_job_tagging( AccountId=account_id, JobId=job_id, Tags=[ {'Key': 'Environment', 'Value': 'Development'}, {'Key': 'Team', 'Value': 'DataProcessing'} ] ) print(f"Additional tags were added to job {job_id}") except ClientError as e: print(f"Error adding job tags: {e}") raise-
有关 API 详细信息,请参阅《Amazon SDK for Python (Boto3) API Reference》中的 PutJobTagging。
-
- SAP ABAP
-
- 适用于 SAP ABAP 的 SDK
-
注意
查看 GitHub,了解更多信息。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 TRY. lo_s3c->putjobtagging( iv_accountid = iv_account_id iv_jobid = iv_job_id it_tags = VALUE /aws1/cl_s3cs3tag=>tt_s3tagset( ( NEW /aws1/cl_s3cs3tag( iv_key = 'Environment' iv_value = 'Development' ) ) ( NEW /aws1/cl_s3cs3tag( iv_key = 'Team' iv_value = 'DataProcessing' ) ) ) ). MESSAGE |Tags added to job { iv_job_id }| TYPE 'I'. CATCH /aws1/cx_s3cnotfoundexception INTO DATA(lo_ex_nf). MESSAGE lo_ex_nf->get_text( ) TYPE 'I'. RAISE EXCEPTION TYPE /aws1/cx_rt_generic EXPORTING previous = lo_ex_nf. CATCH /aws1/cx_s3ctoomanytagsex INTO DATA(lo_ex_tags). MESSAGE lo_ex_tags->get_text( ) TYPE 'I'. RAISE EXCEPTION TYPE /aws1/cx_rt_generic EXPORTING previous = lo_ex_tags. CATCH /aws1/cx_s3cclientexc INTO DATA(lo_ex_cli). MESSAGE lo_ex_cli->get_text( ) TYPE 'I'. RAISE EXCEPTION TYPE /aws1/cx_rt_generic EXPORTING previous = lo_ex_cli. CATCH /aws1/cx_s3cserverexc INTO DATA(lo_ex_srv). MESSAGE lo_ex_srv->get_text( ) TYPE 'I'. RAISE EXCEPTION TYPE /aws1/cx_rt_generic EXPORTING previous = lo_ex_srv. ENDTRY.-
有关 API 详细信息,请参阅《Amazon SDK for SAP ABAP API Reference》中的 PutJobTagging。
-
有关 Amazon SDK 开发人员指南和代码示例的完整列表,请参阅 使用 Amazon SDK 通过 Amazon S3 进行开发。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。
GetJobTagging
UpdateJobPriority