Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Use PutJobTagging
with an Amazon SDK
The following code example shows 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
-
/**
* 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 a complete list of Amazon SDK developer guides and code examples, see
Developing with Amazon S3 using the Amazon SDKs.
This topic also includes information about getting started and details about previous SDK versions.