Invoke and customize Amazon Bedrock models with Step Functions
You can integrate Step Functions with Amazon Bedrock to invoke a specified Amazon Bedrock model and create a fine-tuning job to customize a model. This
page lists the supported Amazon Bedrock APIs and provides an example Task
state to extract the result of a model invocation.
Step Functions can control certain Amazon services directly from Using Amazon States Language to define Step Functions workflows (ASL). To learn more, see Integrating other services and Passing parameters to a service API in Step Functions.
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 |
The Amazon Bedrock service integration API request body includes the following additional parameters.
The following example shows the syntax for InvokeModel API for Amazon Bedrock integration.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 How Step Functions generates 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.