Menu
AWS Step Functions
Developer Guide

Job Status Poller

This sample project creates an AWS Batch job status poller. It implements an AWS Step Functions state machine that uses AWS Lambda to create a Wait state loop that checks on an AWS Batch job. This sample project creates and configures all resources so that your Step Functions workflow will submit an AWS Batch job, and will wait for that job to complete before ending successfully.

This sample project creates the state machine, two Lambda functions, an AWS Batch queue, and configures the related IAM permissions. For more information on the resources that are created with the Job Status Poller sample project, see:

To create the Job Status Poller state machine and provision all resources:

  1. Log in to the Step Functions console, and choose Create a state machine.

  2. Select Sample Projects and choose Job Status Poller.

    The state machine Code and Visual Workflow are displayed.

    Job status poller visual workflow

    Note

    The Code section in this state machine references the AWS resources that will be created for this sample project.

  3. Choose Create Sample Project.

    The Create Project Resources window is displayed, listing the resources that will be created. For this sample project the resources include:

    • A SubmitJob Lambda function

    • A CheckJob Lambda function

    • A SampleJobQueue Batch Job Queue

    Note

    It can take up to 10 minutes as these resources and related IAM permissions are created. While the Create Project Resources window displays Creating resources, you can open the Stack ID link to see which resources are being provisioned.

    Once complete, the New execution window is displayed, with example input similar to this:

    { "jobName": "my-job", "jobDefinition": "arn:aws:batch:us-east-2:123456789012:job-definition/SampleJobDefinition-343f54b445d5312:1", "jobQueue": "arn:aws:batch:us-east-2:123456789012:job-queue/SampleJobQueue-4d9d696031e1449", "wait_time": 60 }

Starting an Execution

After you create your state machine, you can start an execution.

To start a new execution

  1. On the New execution page, enter an execution name (optional) and choose Start Execution.

  2. (Optional) To help identify your execution, you can specify an ID for it in the Enter your execution id here box. If you don't enter an ID, Step Functions generates a unique ID automatically.

    Note

    Step Functions allows you to create state machine, execution, and activity names that contain non-ASCII characters. These non-ASCII names do not work with CloudWatch. To ensure that you can track CloudWatch metrics, choose a name that uses only ASCII characters.

  3. Optionally, you can go to the newly-created state machine on the Step Functions Dashboard, select New execution, and enter the input code using the names or Amazon Resource Names of your newly created resources.

    For instance, the input for the above execution using only the resource names would be:

    { "jobName": "my-job", "jobDefinition": "SampleJobDefinition-343f54b445d5312", "jobQueue": "SampleJobQueue-4d9d696031e1449", "wait_time": 60 }

    Note

    wait_time instructs the Wait state to loop every sixty seconds.

  4. Choose Start Execution.

    A new execution of your state machine starts, and a new page showing your running execution is displayed.

  5. (Optional) In the Execution Details section, choose Info to view the Execution Status and the Started and Closed timestamps.

  6. To view the changing status of your AWS Batch job and the looping results of your execution, choose Output.

    State machine execution.

On this page: