Call Amazon Bedrock with Step Functions - Amazon Step Functions
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).

Call Amazon Bedrock with Step Functions

Step Functions can control certain Amazon services directly from Amazon States Language (ASL). To learn more, see Working with other services and Pass parameters to a service API.

Amazon Bedrock service integration APIs

To integrate Amazon Step Functions with Amazon Bedrock, you can use the following APIs. These APIs are similar to the corresponding Amazon Bedrock APIs, with some differences in the request fields that are passed.

The following table describes the differences between each service integration API and its corresponding Amazon Bedrock API.

Amazon Bedrock service integration APIs and corresponding Amazon Bedrock APIs
Amazon Bedrock service integration API Corresponding Amazon Bedrock API Differences

InvokeModel

Invokes the specified Amazon Bedrock model to run inference using the input you provide in the request body. You use InvokeModel to run inference for text models, image models, and embedding models.

InvokeModel

The Amazon Bedrock service integration API request body includes the following additional parameters.

  • Body – Specifies input data in the format specified in the content-type request header. Body contains parameters specific to the target model.

    If you use the InvokeModel API, you must specify the Body parameter. Step Functions doesn't validate the input you provide in Body.

    When you specify Body using the Amazon Bedrock optimized integration, you can specify a payload of up to 256 KB. If your payload exceeds 256 KB, we recommend that you use Input.

  • Input – Specifies the source to retrieve the input data from. This optional field is specific to Amazon Bedrock optimized integration with Step Functions. In this field, you can specify an S3Uri.

    You can specify either Body in the Parameters or Input, but not both.

    When you specify Input without specifying ContentType, the content type of the input data source becomes the value for ContentType.

  • Output – Specifies the destination where the API response is written. This optional field is specific to Amazon Bedrock optimized integration with Step Functions. In this field, you can specify an S3Uri.

    If you specify this field, the API response body is replaced with a reference to the Amazon S3 location of the original output.

The following example shows the syntax for InvokeModel API for Amazon Bedrock integration.

{ "ModelId": String, // required "Accept": String, // default: application/json "ContentType": String, // default: application/json "Input": { // not from Bedrock API "S3Uri": String }, "Output": { // not from Bedrock API "S3Uri": String } }

CreateModelCustomizationJob

Creates a fine-tuning job to customize a base model.

CreateModelCustomizationJob None

CreateModelCustomizationJob.sync

Creates a fine-tuning job to customize a base model.

CreateModelCustomizationJob None

For information about how to configure IAM permissions when using Step Functions with other Amazon services, see IAM Policies for integrated services.

Task state definition for Amazon Bedrock integration

The following Task state definition shows how you can integrate with Amazon Bedrock in your state machines. This example shows a Task state that extracts the full result of model invocation specified by the path, result_one. This is based on Inference parameters for foundation models. This example uses the Cohere Command large language model (LLM).

{ "Type": "Task", "Resource": "arn:aws:states:::bedrock:invokeModel", "Parameters": { "ModelId": "cohere.command-text-v14", "Body": { "prompt.$": "$.prompt_one", "max_tokens": 250 }, "ContentType": "application/json", "Accept": "*/*" }, "ResultPath": "$.result_one", "ResultSelector": { "result_one.$": "$.Body.generations[0].text" }, "End": true }
Tip

To deploy an example of a state machine that integrates with Amazon Bedrock to your Amazon Web Services account, see Perform AI prompt-chaining with Amazon Bedrock.