Yandex Cloud
Search
Discuss with expertTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
    • Cloud Interconnect
    • Cloud Backup
    • Cloud Registry
    • Yandex AI Studio
    • Compute Cloud
    • Object Storage
    • Managed Service for Kubernetes®
    • Yandex BareMetal
    • Smart Web Security
    • Security Deck
    • Managed Service for PostgreSQL
    • Managed Service for ClickHouse®
    • Monium
    • Cloud CDN
    • Network Load Balancer
    • Virtual Private Cloud
    • Cloud DNS
    • Application Load Balancer
    • Yandex Cloud Video
    • Stackland
    • Yandex Cloud Router
    • Yandex Managed Service for Trino
    • Managed Service for MySQL®
    • Managed Service for Valkey™
    • Managed Service for Apache Spark™
    • Yandex StoreDoc
    • Managed Service for OpenSearch
    • Managed Service for Apache Kafka®
    • Data Transfer
    • Yandex MPP Analytics Engine for PostgreSQL
    • Yandex Managed Service for Apache Airflow®
    • Data Processing
    • Yandex MetaData Hub
    • Managed Service for YDB
    • Managed Service for Sharded PostgreSQL
    • Managed Service for YTsaurus
    • Yandex WebSQL
    • DataLens
    • Yandex Search API
    • SpeechSense
    • SpeechKit
    • DataSphere
    • Vision OCR
    • Translate
    • Yandex Identity Hub
    • Key Management Service
    • Certificate Manager
    • Yandex Lockbox
    • Audit Trails
    • SmartCaptcha
    • Cloud Desktop
    • SourceCraft Code Assistant
    • Container Registry
    • Managed Service for GitLab
    • Managed Service for Prometheus®
    • Cloud Functions
    • API Gateway
    • Yandex Cloud Postbox
    • Message Queue
    • Serverless Integrations
    • IoT Core
    • Data Streams
    • Serverless Containers
    • Cloud Notification Service
    • Yandex Query
    • Identity and Access Management
    • Yandex Cloud Console
    • Resource Manager
    • Yandex Cloud Billing
    • Yandex Cloud Quota Manager
    • Cloud Apps
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2026 Direct Cursus Technology L.L.C.
Yandex API Gateway
  • Getting started
    • All tutorials
      • Deploying a web application using the Java Servlet API
      • Developing a custom integration
      • Developing CRUD APIs for a movie service
      • Building an interactive serverless application using WebSocket
      • Working with an API gateway via WebSocket
      • Running a containerized app in Yandex Serverless Containers
      • Deploying a web app with JWT authorization in API Gateway and Firebase authentication
      • Canary release of a function in Cloud Functions
      • Interactive debugging of functions in Cloud Functions
  • Access management
  • Tools
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Public materials
  • Release notes
  • FAQ

In this article:

  • Getting started
  • Required paid resources
  • Set up your environment
  • Create an Yandex Object Storage bucket
  • Create a Yandex Managed Service for YDB database
  • Create Cloud Functions
  • Create an API gateway
  • Test the application
  • How to delete the resources you created
  1. Tutorials
  2. Serverless-based backend
  3. Deploying a web application using the Java Servlet API

Deploying a web application using the Java Servlet API

Written by
Yandex Cloud
Improved by
Danila N.
Updated at July 29, 2026
View in Markdown
  • Getting started
    • Required paid resources
  • Set up your environment
  • Create an Yandex Object Storage bucket
  • Create a Yandex Managed Service for YDB database
  • Create Cloud Functions
  • Create an API gateway
  • Test the application
  • How to delete the resources you created

Learn how to use the serverless technology and Java Servlet API to create a simple web application for managing a to-do list.

To create a web app:

  1. Get your cloud ready.
  2. Set up your environment.
  3. Create a Yandex Object Storage bucket.
  4. Create a YDB.
  5. Create Yandex Cloud Functions.
  6. Create an API gateway.
  7. Test your application.

If you no longer need the resources you created, delete them.

Getting startedGetting started

Sign up for Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or create a new account.
  2. On the Yandex Cloud Billing page, make sure you have a billing account linked and it has the ACTIVE or TRIAL_ACTIVE status. If you do not have a billing account, create one and link a cloud to it.

If you have an active billing account, you can create or select a folder for your infrastructure on the cloud page.

Learn more about clouds and folders here.

Required paid resourcesRequired paid resources

The cost of resources for web application support includes:

  • Fee for the number of requests to the API gateway and outgoing traffic (see Yandex API Gateway pricing).
  • Fee for YDB operations and data storage (see Yandex Managed Service for YDB pricing).
  • Fee for the number of function calls, computing resources allocated for the function, and outgoing traffic (see Cloud Functions pricing).

Set up your environmentSet up your environment

  1. Create a service account and assign it the following roles for your folder:

    • functions.functionInvoker
    • storage.viewer
    • ydb.editor.
  2. Clone the repository with the project:

    git clone https://github.com/yandex-cloud-examples/yc-serverless-servlet
    
  3. Add the contents of the yc-serverless-servlet local repository you cloned to the servlet.zip archive. You will need this archive later to create functions in Yandex Cloud Functions.

Create an Yandex Object Storage bucketCreate an Yandex Object Storage bucket

Create a bucket and upload index.html to it:

Management console
CLI
  1. In the management console, select the folder where you want to create a bucket.

  2. Navigate to Object Storage.

  3. Click Create bucket, and in the window that opens:

    1. Enter a bucket name consistent with the naming conventions.
    2. Limit the maximum bucket size, if required.
    3. In the Read objects, Read object list, and Read settings fields, select With authorization.
    4. Select the default storage class.
    5. Click Create bucket.
  4. Select the bucket you created.

  5. Click Upload in the top-right corner of the page. In the project's folder, select src/main/resources/index.html.

  6. Select the storage class for the file and click Upload.

If you do not have the Yandex Cloud CLI yet, install and initialize it.

The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. To create a bucket, run this command, specifying a unique bucket name:

    yc storage bucket create \
      --name <bucket_name> \
      --default-storage-class standard
    

    Result:

    name: sample-bucket
    folder_id: b1g5bhjofg7o********
    anonymous_access_flags: {}
    default_storage_class: STANDARD
    versioning: VERSIONING_DISABLED
    created_at: "2026-06-01T04:44:30.688587Z"
    resource_id: e3eqmpmknkus********
    

    For more information about the yc storage bucket create command, see the CLI reference.

  2. To upload the index.html file to the bucket, run this command:

    yc storage s3api put-object \
      --bucket <bucket_name> \
      --key index.html \
      --body "<local_path_to_file>" \
      --content-type "text/html"
    

    Where:

    • --bucket: Name of the bucket you created earlier.
    • --body: Local path to index.html you pulled from the repository. Here is an example: /Users/myuser/repositories/yc-serverless-servlet/src/main/resources/index.html.

    Result:

    etag: '"f38989ca9039c275f5f56840********"'
    request_id: 72d413fc********
    

    For more information about the yc storage s3api put-object command, see the CLI reference.

Create a Yandex Managed Service for YDB databaseCreate a Yandex Managed Service for YDB database

Management console
CLI
  1. Create a database in serverless mode:

    1. In the management console, select the folder where you created the bucket.
    2. Navigate to Managed Service for YDB.
    3. Click Create a database.
    4. Specify the database Name.
    5. Under Database type, select Serverless.
    6. Click Create a database.
    7. Wait for the database to start. While being created, your database will have the Provisioning status. Once it is ready for use, its status will change to Running.
    8. Select the created database.
    9. Under Connection, find the Endpoint field and save its value. You will need it later to create functions.
  2. Create a table named Tasks:

    1. To open the database root directory, in the left-hand menu, select  Navigation.

    2. To query your database, click New SQL query in the top-right corner. On the Query page that opens:

      1. In the Query field, enter:

        CREATE TABLE Tasks (
          TaskId Utf8,
          Name Utf8,
          Description Utf8,
          CreatedAt Datetime,
          PRIMARY KEY (TaskId)
        );
        
      2. Click Run.

  1. Create a database in serverless mode, specifying its name in this command:

    yc ydb database create <DB_name> \
      --serverless
    

    Result:

    done (22s)
    id: etnm3b9gco6k********
    folder_id: b1g5bhjofg7o********
    created_at: "2026-06-01T04:54:48Z"
    name: sample-database
    status: PROVISIONING
    endpoint: grpcs://ydb.serverless.yandexcloud.net:2135/?database=/ru-central1/b1gj9ja2h4ct********/etnm3b9gco6k********
    serverless_database:
      storage_size_limit: "53687091200"
    location_id: ru-central1
    backup_config:
      backup_settings:
        - name: daily
          backup_schedule:
            daily_backup_schedule:
              execute_time:
                hours: 17
          backup_time_to_live: 604800s
          type: SYSTEM
    document_api_endpoint: https://docapi.serverless.yandexcloud.net/ru-central1/b1gj9ja2h4ct********/etnm3b9gco6k********
    monitoring_config: {}
    

    Save the value of the endpoint field. You will need this name at the next steps.

    For more information about the yc ydb database create command, see the CLI reference.

  2. Install the YDB CLI utility for managing YDB databases.

  3. Save the IAM token for authentication of queries via YDB CLI to the IAM_TOKEN environment variable:

    export IAM_TOKEN=$(yc iam create-token)
    
  4. Create a table named Tasks:

    ydb \
      --endpoint grpcs://ydb.serverless.yandexcloud.net:2135 \
      --database "/ru-central1/b1gj9ja2h4ct********/etnjkrvloo7k********" \
      scripting yql -s \
      "CREATE TABLE Tasks
      (
        TaskId Utf8,
        Name Utf8,
        Description Utf8,
        CreatedAt Datetime,
        PRIMARY KEY (TaskId)
      );"
    

    Where:

    • --endpoint: First part of the endpoint field value saved when creating the database (preceding /?database=), e.g., grpcs://ydb.serverless.yandexcloud.net:2135.
    • --database: Second part of the endpoint field value (following /?database=). Here is an example: /ru-central1/b1gj9ja2h4ct********/etnjkrvloo7k********.

Create Cloud FunctionsCreate Cloud Functions

Create a function for each servlet:

Management console
CLI
  1. In the management console, navigate to the folder where you created the bucket and the database.
  2. Navigate to Cloud Functions.
  3. Click Create function.
  4. Specify add-task for the function Name and, optionally, add a Description.
  5. Click Create.
  6. Under Editor, select Java 21 as the runtime, disable Add files with code examples, and click Continue.
  7. Prepare the function code. To do this, select ZIP archive in the Code source field.
  8. In the File field, click Attach file and select servlet.zip you created earlier.
  9. In the Entry point field, enter yandex.cloud.examples.serverless.todo.AddTaskServlet.
  10. Set Timeout to 10.
  11. In the Service account field, select the account you created when setting up your environment.
  12. Add these environment variables:
    • ENDPOINT: Enter the first part of the Endpoint field value you saved when creating a YDB database (the one between grpcs:// and /?database=), e.g., ydb.serverless.yandexcloud.net:2135.
    • DATABASE: Enter the second part of the Endpoint field value (following /?database=), e.g., /ru-central1/r1gra875baom********/g5n22e7ejfr1********.
  13. Click Save changes and wait for the function version to compile.
  14. On the Overview page that opens, enable Public function.
  15. Repeat steps 3 through 14 to create a function named list-tasks with the yandex.cloud.examples.serverless.todo.ListTasksServlet entry point.
  16. Repeat steps 3 through 14 to create a function named delete-task with the yandex.cloud.examples.serverless.todo.DeleteTaskServlet entry point.
  1. Create a function named add-task:

    yc serverless function create \
      --name add-task
    

    Result:

    id: d4e3reah34e0********
    folder_id: b1g5bhjofg7o********
    created_at: "2026-06-01T05:07:13.071Z"
    name: add-task
    http_invoke_url: https://functions.yandexcloud.net/d4e3reah34e0********
    status: ACTIVE
    

    Save the id of your new function. You will need it later to create an API gateway.

    For more information about the yc serverless function create command, see the CLI reference.

  2. Create a version of the add-task function:

    yc serverless function version create \
      --function-name add-task \
      --runtime java21 \
      --service-account-id <service_account_ID> \
      --entrypoint "yandex.cloud.examples.serverless.todo.AddTaskServlet" \
      --memory 128m \
      --execution-timeout 10s \
      --source-path "./servlet.zip" \
      --environment ENDPOINT="<YDB_endpoint>",DATABASE="<DB_name>"
    

    Where:

    • --function-name: Name of the function whose version you want to create.

    • --runtime: Runtime.

    • --service-account-id: ID of the service account you created when setting up your environment.

    • --entrypoint: Entry point in <function_file_name>.<handler_name> format.

    • --memory: RAM amount available to the function.

    • --execution-timeout: Maximum function execution time before timeout.

    • --source-path: Local path to the previously created servlet.zip archive with the function code and required dependencies.

    • --environment: Environment variables in key=value format:

      • ENDPOINT: First part of the endpoint field value you saved when creating your database (the one between grpcs:// and /?database=), e.g., ydb.serverless.yandexcloud.net:2135.
      • DATABASE: Second part of the endpoint field value (following /?database=). Here is an example: /ru-central1/b1gj9ja2h4ct********/etnjkrvloo7k********.

    Result:

    done (52s)
    id: d4eve0ahaf3e********
    function_id: d4e3reah34e0********
    created_at: "2026-06-01T05:18:34.900Z"
    ...
    log_options:
      folder_id: b1g5bhjofg7o********
    

    For more information about the yc serverless function version create command, see the CLI reference.

  3. Make the function public:

    yc serverless function allow-unauthenticated-invoke add-task
    

    For more information about the yc serverless function allow-unauthenticated-invoke command, see the CLI reference.

  4. Repeat steps 1 through 3 to create a function named list-tasks with the yandex.cloud.examples.serverless.todo.ListTasksServlet entry point.

  5. Repeat steps 1 through 3 to create a function named delete-task with the yandex.cloud.examples.serverless.todo.DeleteTaskServlet entry point.

Create an API gatewayCreate an API gateway

To enable interaction between services, create an API gateway:

Management console
CLI
  1. In the management console, select the folder where you created your bucket, database, and functions.

  2. Navigate to API Gateway.

  3. Click Create API gateway.

  4. Specify the gateway Name and, optionally, add a Description.

  5. In the Specification field, add this specification:

    openapi: 3.0.0
    info:
      title: ToDo list
      version: 1.0.0
    paths:
      /:
        get:
          x-yc-apigateway-integration:
            type: object-storage
            bucket: <bucket_name>
            object: index.html
            presigned_redirect: false
            service_account_id: <service_account_ID>
          operationId: static
      /add:
          post:
            x-yc-apigateway-integration:
              type: cloud-functions
              function_id: <add-task_function_ID>
            operationId: addTask
      /list:
        get:
          x-yc-apigateway-integration:
            type: cloud-functions
            function_id: <list-tasks_function_ID>
          operationId: listTasks
      /delete:
        delete:
          x-yc-apigateway-integration:
            type: cloud-functions
            function_id: <delete-task_function_ID>
          operationId: deleteTask
    

    Where:

    • bucket: Name of the bucket to which you uploaded the index.html file.
    • service_account_id: ID of the service account you created when setting up your environment.
    • /add section, function_id parameter: add-task function ID.
    • /list section, function_id parameter: list-tasks function ID.
    • /delete section, function_id parameter: delete-task function ID.
  6. Click Create.

  7. In the list of API gateways that opens, click the one you created and save its URL (the Default domain field value).

  1. Create a file named todo.yaml and save the following specification to it:

    openapi: 3.0.0
    info:
      title: ToDo list
      version: 1.0.0
    paths:
      /:
        get:
          x-yc-apigateway-integration:
            type: object-storage
            bucket: <bucket_name>
            object: index.html
            presigned_redirect: false
            service_account_id: <service_account_ID>
          operationId: static
      /add:
          post:
            x-yc-apigateway-integration:
              type: cloud-functions
              function_id: <add-task_function_ID>
            operationId: addTask
      /list:
        get:
          x-yc-apigateway-integration:
            type: cloud-functions
            function_id: <list-tasks_function_ID>
          operationId: listTasks
      /delete:
        delete:
          x-yc-apigateway-integration:
            type: cloud-functions
            function_id: <delete-task_function_ID>
          operationId: deleteTask
    

    Where:

    • bucket: Name of the bucket to which you uploaded the index.html file.
    • service_account_id: ID of the service account you created when setting up your environment.
    • /add section, function_id parameter: add-task function ID you saved earlier.
    • /list section, function_id parameter: list-tasks function ID you saved earlier.
    • /delete section, function_id parameter: delete-task function ID you saved earlier.
  2. Create your API gateway by specifying the local path to the todo.yaml file you created earlier in this command:

    yc serverless api-gateway create \
      --name todo-list \
      --spec "./todo.yaml" \
      --description "simple todo list"
    

    Result:

    done (2s)
    id: d5d9ut8546r7********
    folder_id: b1g5bhjofg7o********
    created_at: "2026-06-01T05:49:08.648Z"
    name: todo-list
    description: simple todo list
    status: ACTIVE
    domain: d5d9ut8546r7********.wnq2w1o5.apigw.yandexcloud.net
    connectivity: {}
    log_options:
      folder_id: b1g5bhjofg7o********
    execution_timeout: 300s
    

    Save the domain name (the domain field value) of your new API gateway. The gateway will be available at https://<domain_name>.

    For more information about the yc serverless api-gateway create command, see the CLI reference.

Test the applicationTest the application

To open the application, navigate to your new API gateway's URL in your browser. If everything is configured correctly, you will be able to create, view, and delete tasks in the application that opens.

How to delete the resources you createdHow to delete the resources you created

To stop paying for the resources you created:

  • Delete the API gateway.
  • Delete the functions.
  • Delete the database.
  • Delete the index.html file, then delete the bucket.

The naming requirements are as follows:

  • Length: between 3 and 63 characters.
  • It can only contain lowercase Latin letters, numbers, and hyphens.
  • It must start with a letter and cannot end with a hyphen.

The bucket name must be unique within Yandex Object Storage. For more information, see Naming buckets.

Yandex Object Storage allows you to store objects in storages of various classes depending on how long you want to store your objects and how often you access them. For more information, see Storage class.

Serverless YDB databases require zero configuration, administration, load monitoring, or resource management from the user. For more information, see Serverless and dedicated operation modes.

With Yandex Cloud Functions functions, you can place your code in Yandex Cloud and run on request or trigger. For more information, see Function.

A bucket is a portion of Yandex Object Storage allocated for user data. For more information, see Bucket in Object Storage.

An API gateway is an interface for working with services on the internet or within Yandex Cloud, set in a declarative way using a specification. For more information, see Resource relationships in API Gateway.

A role is a set of permissions that defines the allowed scope of operations with Yandex Cloud resources. For more information, see Roles.

Was the article helpful?

Previous
All tutorials
Next
Developing a custom integration
© 2026 Direct Cursus Technology L.L.C.