Search in sources :

Example 1 with ExecutionListItem

use of com.amazonaws.services.stepfunctions.model.ExecutionListItem in project aws-doc-sdk-examples by awsdocs.

the class StepFunctionsSample method main.

public static void main(String[] args) throws Exception {
    /*
         * The ProfileCredentialsProvider will return your [default]
         * credential profile by reading from the credentials file located at
         * (~/.aws/credentials).
         *
         * It is possible to use another profile with:
         *  credentialsProvider = new ProfileCredentialsProvider("your-profile")
         */
    ProfileCredentialsProvider credentialsProvider = new ProfileCredentialsProvider();
    try {
        credentialsProvider.getCredentials();
    } catch (Exception e) {
        throw new AmazonClientException("Cannot load the credentials from the credential profiles " + "file. Please make sure that your credentials file is " + "at the correct location (~/.aws/credentials), and is " + "in valid format.", e);
    }
    Regions region = Regions.US_EAST_1;
    AWSStepFunctions sfnClient = AWSStepFunctionsClientBuilder.standard().withCredentials(credentialsProvider).withRegion(region).build();
    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon Step Functions");
    System.out.println("===========================================\n");
    try {
        System.out.println("Listing state machines");
        ListStateMachinesResult listStateMachinesResult = sfnClient.listStateMachines(new ListStateMachinesRequest());
        List<StateMachineListItem> stateMachines = listStateMachinesResult.getStateMachines();
        System.out.println("State machines count: " + stateMachines.size());
        if (!stateMachines.isEmpty()) {
            stateMachines.forEach(sm -> {
                System.out.println("\t- Name: " + sm.getName());
                System.out.println("\t- Arn: " + sm.getStateMachineArn());
                ListExecutionsRequest listRequest = new ListExecutionsRequest().withStateMachineArn(sm.getStateMachineArn());
                ListExecutionsResult listExecutionsResult = sfnClient.listExecutions(listRequest);
                List<ExecutionListItem> executions = listExecutionsResult.getExecutions();
                System.out.println("\t- Total: " + executions.size());
                executions.forEach(ex -> {
                    System.out.println("\t\t-Start: " + ex.getStartDate());
                    System.out.println("\t\t-Stop: " + ex.getStopDate());
                    System.out.println("\t\t-Name: " + ex.getName());
                    System.out.println("\t\t-Status: " + ex.getStatus());
                    System.out.println();
                });
            });
        }
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means" + " your request made it to Amazon Step Functions, but was" + " rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means " + "the client encountered a serious internal problem while " + "trying to communicate with Step Functions, such as not " + "being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}
Also used : ListStateMachinesRequest(com.amazonaws.services.stepfunctions.model.ListStateMachinesRequest) AmazonClientException(com.amazonaws.AmazonClientException) Regions(com.amazonaws.regions.Regions) ListStateMachinesResult(com.amazonaws.services.stepfunctions.model.ListStateMachinesResult) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonClientException(com.amazonaws.AmazonClientException) ListExecutionsResult(com.amazonaws.services.stepfunctions.model.ListExecutionsResult) AWSStepFunctions(com.amazonaws.services.stepfunctions.AWSStepFunctions) AmazonServiceException(com.amazonaws.AmazonServiceException) ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) StateMachineListItem(com.amazonaws.services.stepfunctions.model.StateMachineListItem) ExecutionListItem(com.amazonaws.services.stepfunctions.model.ExecutionListItem) ListExecutionsRequest(com.amazonaws.services.stepfunctions.model.ListExecutionsRequest)

Aggregations

AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonServiceException (com.amazonaws.AmazonServiceException)1 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)1 Regions (com.amazonaws.regions.Regions)1 AWSStepFunctions (com.amazonaws.services.stepfunctions.AWSStepFunctions)1 ExecutionListItem (com.amazonaws.services.stepfunctions.model.ExecutionListItem)1 ListExecutionsRequest (com.amazonaws.services.stepfunctions.model.ListExecutionsRequest)1 ListExecutionsResult (com.amazonaws.services.stepfunctions.model.ListExecutionsResult)1 ListStateMachinesRequest (com.amazonaws.services.stepfunctions.model.ListStateMachinesRequest)1 ListStateMachinesResult (com.amazonaws.services.stepfunctions.model.ListStateMachinesResult)1 StateMachineListItem (com.amazonaws.services.stepfunctions.model.StateMachineListItem)1