Use PutJobTagging with an AWS SDK
The following code examples show how to use PutJobTagging.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:
- Java
-
- SDK for Java 2.x
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. /** * 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 }); }-
For API details, see PutJobTagging in AWS SDK for Java 2.x API Reference.
-
- Python
-
- SDK for Python (Boto3)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. 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-
For API details, see PutJobTagging in AWS SDK for Python (Boto3) API Reference.
-
- SAP ABAP
-
- SDK for SAP ABAP
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. 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.-
For API details, see PutJobTagging in AWS SDK for SAP ABAP API reference.
-
For a complete list of AWS SDK developer guides and code examples, see Developing with Amazon S3 using the AWS SDKs. This topic also includes information about getting started and details about previous SDK versions.