ListJobs.java - AWS Code Sample

This version of the AWS Code Sample Catalog has been replaced by the AWS Code Library, which contains new and updated code examples.

ListJobs.java

ListJobs.java demonstrates how to list active and complete Amazon S3 Batch Operations.

/** * Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * <p> * This file is licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. A copy of * the License is located at * <p> * http://aws.amazon.com/apache2.0/ * <p> * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ package aws.example.s3control; import com.amazonaws.AmazonServiceException; import com.amazonaws.SdkClientException; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.services.s3control.AWSS3Control; import com.amazonaws.services.s3control.AWSS3ControlClient; import com.amazonaws.services.s3control.model.JobListDescriptor; import com.amazonaws.services.s3control.model.ListJobsRequest; import com.amazonaws.services.s3control.model.ListJobsResult; import static com.amazonaws.regions.Regions.US_WEST_2; public class ListJobs { public static void main(String[] args) { String accountId = "Account ID"; try { AWSS3Control s3ControlClient = AWSS3ControlClient.builder() .withCredentials(new ProfileCredentialsProvider()) .withRegion(US_WEST_2) .build(); ListJobsResult result = s3ControlClient.listJobs(new ListJobsRequest() .withAccountId(accountId) .withMaxResults(20) .withJobStatuses("Active", "Complete") ).withJobs(new JobListDescriptor() .withStatus("Active") .withStatus("Complete")); for (JobListDescriptor jobSummary : result.getJobs()) { System.out.printf("%s - %s (status: %s)\n", jobSummary.getJobId(), jobSummary.getCreationTime(), jobSummary.getStatus()); } } catch (AmazonServiceException e) { // The call was transmitted successfully, but Amazon S3 couldn't process // it and returned an error response. e.printStackTrace(); } catch (SdkClientException e) { // Amazon S3 couldn't be contacted for a response, or the client // couldn't parse the response from Amazon S3. e.printStackTrace(); } } }

Sample Details

Service: s3

Last tested: 2019-04-30

Author: jschwarzwalder (AWS)

Type: full-example