> ## Documentation Index
> Fetch the complete documentation index at: https://anaconda.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate text with Amazon Bedrock

This tutorial walks you through connecting Anaconda Platform to Amazon Bedrock so you can run text generation tasks from your workstations and Metaflow flows.

By the end of this tutorial, you will have:

* An IAM role that allows Anaconda Platform to interact with Bedrock
* A workstation notebook that lists available models and runs text generation
* A Metaflow flow that invokes a Bedrock model

## Create Bedrock resources

AWS Bedrock requires an IAM role with permissions to invoke foundation models, and access to the models you want to use. For the full setup guide, see the [AWS Bedrock getting started documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/getting-started.html).

Create an IAM role with permissions to invoke Bedrock models. Request access to the foundation models you plan to use in the Bedrock console.

## Chain the Bedrock role with the platform task role

To allow Anaconda Platform tasks to use your Bedrock role, register it as an integration in the platform:

1. Select **Integrations** in the left-hand navigation.

2. Click **AWS** in the **Add an Integration** section.

3. Enter a name for the integration.

4. Enter a description for the integration.

5. Enter the ARN of the IAM role you created.

   <Note>
     If you need the ARN, expand the **Getting your IAM role ARN** section in the panel.

     This shows the trust policy statement you need to add to your role, and the tag key and value required for the platform to discover it. You can choose to use an existing target role or create a new one—the panel shows the required trust policy and tagging steps for either path.
   </Note>

6. Click **Add**.

After the integration is created, the **How to use** tab in the integration panel shows a code snippet with the exact `role_arn` value for your flows. Copy this snippet into your Metaflow steps to access Bedrock through the chained role.

## Download the tutorial content

Download the tutorial content to your workstation:

```bash theme={null}
outerbounds tutorials pull --url https://outerbounds-journeys-content.s3.us-west-2.amazonaws.com/main/journeys.tar.gz --destination-dir ~/learn
```

The Bedrock tutorial content is in `~/learn/bedrock`. If you prefer a different location, replace `~/learn` with a directory of your choice.

<Tip>
  This command downloads all tutorial content as a single bundle. If you've already worked through other tutorials, you likely already have this and do not need to run the command again.
</Tip>

## Generate text from a workstation notebook

Open the notebook in `00-nb` from the `~/learn/bedrock` directory. Before running it, update the `role_arn` variable with the IAM role you created earlier. This notebook walks you through listing available Bedrock models and running text generation tasks.

## Generate text from a Metaflow flow

Open the `01-flow` directory from the `~/learn/bedrock` directory. This directory contains a Metaflow flow that invokes a Bedrock model. Before running it, update the `MY_BEDROCK_ROLE` variable in `flow.py` with the same role ARN you used in the notebook.

Run the flow:

```bash theme={null}
python flow.py run --with kubernetes
```

## Next steps

To build on this tutorial:

* Explore other Bedrock model providers and capabilities.
* Build more complex workflows combining Bedrock with other AWS services.
* Integrate Bedrock into your existing ML pipelines.
