[Yandex Cloud documentation](../../index.md) > [Tutorials](../index.md) > [Serverless technologies](index.md) > Serverless-based workflows and automation > Scheduled image and PDF recognition in an Object Storage bucket

# Scheduled image and PDF recognition in an Object Storage bucket

In this tutorial, you will learn how to use [Yandex Vision OCR](https://aistudio.yandex.ru/docs/en/vision/concepts/ocr/index) to set up automatic recognition of new images (in [supported formats](https://aistudio.yandex.ru/docs/en/vision/concepts/ocr/index#image-requirements)) and PDFs in an [bucket](../../storage/concepts/bucket.md).


## Recognition steps {#ocr}

![image](../../_assets/vision/ocr-storage-recognizer.svg)

1. The user uploads images or documents to the `input` directory ([prefix](../../storage/concepts/object.md#folder)) in a Yandex Object Storage bucket.
1. The [Yandex Cloud Functions](../../functions/index.md) [trigger](../../functions/concepts/trigger/index.md), activated on schedule, checks for new files in the `input` folder. Next, the system sends files to the [Yandex Serverless Containers](../../serverless-containers/index.md) [container](../../serverless-containers/concepts/container.md) for recognition.
1. During the recognition process, the operation ID is stored in the `process` folder of the source bucket.
1. Once the operation is completed, the recognition results are saved to the `result` folder as JSON and TXT files. The operation ID is deleted from the `process` folder.

The infrastructure is built using the [Yandex Cloud Terraform provider](../../terraform/index.md). The source code for this guide is available on [GitHub](https://github.com/yandex-cloud-examples/yc-vision-ocr-recognizer).

To set up automatic image recognition via Vision OCR:
1. [Get your cloud ready](#before-you-begin).
1. [Create the infrastructure](#deploy).
1. [Upload files for recognition and check how the Vision OCR service works](#test).

If you no longer need the resources you created, [delete them](#clear-out).


## Get your cloud ready {#before-begin}

Sign up for Yandex Cloud and create a [billing account](../../billing/concepts/billing-account.md):
1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or create a new account.
1. On the **[Yandex Cloud Billing](https://center.yandex.cloud/billing/accounts)** page, make sure you have a billing account linked and it has the `ACTIVE` or `TRIAL_ACTIVE` [status](../../billing/concepts/billing-account-statuses.md). If you do not have a billing account, [create one](../../billing/quickstart/index.md) and [link](../../billing/operations/pin-cloud.md) a cloud to it.

If you have an active billing account, you can create or select a [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) for your infrastructure on the [cloud page](https://console.yandex.cloud/cloud).

[Learn more about clouds and folders here](../../resource-manager/concepts/resources-hierarchy.md).



### Required paid resources {#paid-resources}

The infrastructure support cost for scheduled image and document recognition includes:
* Fee for data storage in a bucket and data operations (see [Object Storage pricing](../../storage/pricing.md)).
* Fee for using Vision OCR (see [Vision OCR pricing](https://aistudio.yandex.ru/docs/en/vision/pricing)).
* Fee for container invocation count, computing resources allocated to run the application, and outbound traffic (see [Serverless Containers pricing](../../serverless-containers/pricing.md)).
* Fee for storing the [secret](../../lockbox/concepts/secret.md) and operations with it (see [Yandex Lockbox pricing](../../lockbox/pricing.md)).


## Create the infrastructure {#deploy}

With [Terraform](https://www.terraform.io/), you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.

Terraform is distributed under the [Business Source License](https://github.com/hashicorp/terraform/blob/main/LICENSE). The [Yandex Cloud provider for Terraform](https://github.com/yandex-cloud/terraform-provider-yandex) is distributed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/) license.

For more information about the provider resources, see the guides on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../terraform/index.md).

To create your infrastructure via Terraform:
1. [Install Terraform](../infrastructure-management/terraform-quickstart.md#install-terraform), [get the authentication credentials](../infrastructure-management/terraform-quickstart.md#get-credentials), and specify the source for installing the Yandex Cloud provider (see [Configure your provider](../infrastructure-management/terraform-quickstart.md#configure-provider), Step 1).

1. Prepare your infrastructure description files:

    1. Clone the repository containing the configuration files.

        ```bash
        git clone https://github.com/yandex-cloud-examples/yc-vision-ocr-recognizer.git
        ```

    1. Navigate to the `terraform` directory within the repository.

    1. In the `variables.auto.tfvars` file, specify these custom settings:
        * `cloud_id`: Cloud ID.
        * `folder_id`: [Folder ID](../../resource-manager/operations/folder/get-id.md).
        * `zone`: Availability zone.

1. Create the resources:

   1. In the terminal, navigate to the configuration file directory.
   1. Make sure the configuration is correct using this command:
   
      ```bash
      terraform validate
      ```
   
      If the configuration is valid, you will get this message:
   
      ```bash
      Success! The configuration is valid.
      ```
   
   1. Run this command:
   
      ```bash
      terraform plan
      ```
   
      You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
   1. Apply the configuration changes:
   
      ```bash
      terraform apply
      ```
   
   1. Type `yes` and press **Enter** to confirm the changes.

The system will create a bucket named `ocr-recognition-...`.


## Upload files for recognition and check how the Vision OCR service works {#test}

1. [Upload](../../storage/operations/objects/upload.md) the files for recognition to the `input` folder inside the bucket you created earlier.
1. Open the `result` folder in your bucket. The folder should contain the recognition results as TXT and JSON files.


## How to delete the resources you created {#clear-out}

To stop incurring costs for the resources you created:

1. Delete all files from the bucket.
1. Open the `main.tf` configuration file and delete your infrastructure description from it.
1. Apply the changes:

    1. In the terminal, navigate to the configuration file directory.
    1. Make sure the configuration is correct using this command:
    
       ```bash
       terraform validate
       ```
    
       If the configuration is valid, you will get this message:
    
       ```bash
       Success! The configuration is valid.
       ```
    
    1. Run this command:
    
       ```bash
       terraform plan
       ```
    
       You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
    1. Apply the configuration changes:
    
       ```bash
       terraform apply
       ```
    
    1. Type `yes` and press **Enter** to confirm the changes.