Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 2025 Direct Cursus Technology L.L.C.
Yandex Object Storage
    • All tutorials
    • Getting statistics on object queries with S3 Select
    • Getting website traffic statistics with S3 Select
    • Getting statistics on object queries using Yandex Query
    • Generating a resource-by-resource cost breakdown report using S3 Select
    • Server-side encryption
    • Integrating an L7 load balancer with CDN and Object Storage
    • Blue-green and canary deployment of service versions
    • Analyzing logs in DataLens
    • Mounting buckets to the file system of Yandex Data Processing hosts
    • Using Object Storage in Yandex Data Processing
    • Importing data from Object Storage, processing and exporting to Managed Service for ClickHouse®
    • Mounting a bucket as a disk in Windows
    • Migrating data from Yandex Data Streams using Yandex Data Transfer
    • Using hybrid storage in Yandex Managed Service for ClickHouse®
    • Loading data from Yandex Managed Service for OpenSearch to Yandex Object Storage using Yandex Data Transfer
    • Automatically copying objects from one bucket to another
    • Recognizing audio files in a bucket on a regular basis
    • Training a model in Yandex DataSphere on data from Object Storage
    • Connecting to Object Storage from VPC
    • Migrating data to Yandex Managed Service for PostgreSQL using Yandex Data Transfer
    • Uploading data to Yandex Managed Service for Greenplum® using Yandex Data Transfer
    • Uploading data to Yandex Managed Service for ClickHouse® using Yandex Data Transfer
    • Uploading data to Yandex Managed Service for YDB using Yandex Data Transfer
    • Exchanging data between Yandex Managed Service for ClickHouse® and Yandex Data Processing
    • Uploading data from Yandex Managed Service for YDB using Yandex Data Transfer
    • Hosting a static Gatsby website in Object Storage
    • Migrating a database from Managed Service for PostgreSQL to Object Storage
    • Exchanging data between Yandex Managed Service for ClickHouse® and Yandex Data Processing
    • Importing data from Yandex Managed Service for PostgreSQL to Yandex Data Processing using Sqoop
    • Importing data from Yandex Managed Service for MySQL® to Yandex Data Processing using Sqoop
    • Migrating data from Yandex Object Storage to Yandex Managed Service for MySQL® using Yandex Data Transfer
    • Migrating a database from Yandex Managed Service for MySQL® to Yandex Object Storage
    • Exporting Greenplum® data to a cold storage in Yandex Object Storage
    • Loading data from Yandex Direct to a Yandex Managed Service for ClickHouse® data mart using Yandex Cloud Functions, Yandex Object Storage, and Yandex Data Transfer
    • Migrating data from Elasticsearch to Yandex Managed Service for OpenSearch
    • Uploading Terraform states to Object Storage
    • Locking Terraform states using Managed Service for YDB
    • Visualizing Yandex Query data
    • Publishing game updates
    • VM backups using Hystax Acura
    • Backing up to Object Storage with CloudBerry Desktop Backup
    • Backing up to Object Storage with Duplicati
    • Backing up to Object Storage with Bacula
    • Backing up to Yandex Object Storage with Veeam Backup
    • Backing up to Object Storage with Veritas Backup Exec
    • Managed Service for Kubernetes cluster backups in Object Storage
    • Developing a custom integration in API Gateway
    • URL shortener
    • Storing application runtime logs
    • Developing a skill for Alice and a website with authorization
    • Creating an interactive serverless application using WebSocket
    • Deploying a web application using the Java Servlet API
    • Developing a Telegram bot
    • Replicating logs to Object Storage using Fluent Bit
    • Replicating logs to Object Storage using Data Streams
    • Uploading audit logs to ArcSight SIEM
    • Exporting audit logs to SIEM Splunk systems
    • Creating an MLFlow server for logging experiments and artifacts
    • Operations with data using Yandex Query
    • Federated data queries using Query
    • Recognizing text in image archives using Vision OCR
    • Converting a video to a GIF in Python
    • Automating tasks using Managed Service for Apache Airflow™
    • Processing files with usage details in Yandex Cloud Billing
    • Deploying a web app with JWT authorization in API Gateway and authentication in Firebase
    • Searching for Yandex Cloud events in Yandex Query
    • Searching for Yandex Cloud events in Object Storage
    • Creating an external table from a bucket table using a configuration file
    • Migrating databases from Google BigQuery to Managed Service for ClickHouse®
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Bucket logs
  • Release notes
  • FAQ

In this article:

  • Getting started
  • Required paid resources
  • Set up your environment
  • Create an Object Storage bucket
  • Create a Managed Service for YDB database
  • Create Cloud Functions functions
  • Create an API gateway
  • Test the application
  • How to delete the resources you created
  1. Tutorials
  2. 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 May 7, 2025
  • Getting started
    • Required paid resources
  • Set up your environment
  • Create an Object Storage bucket
  • Create a Managed Service for YDB database
  • Create Cloud Functions functions
  • Create an API gateway
  • Test the application
  • How to delete the resources you created

Learn how to use serverless technologies and the Java Servlet API to create a simple web application for managing a task list.

To create a web application:

  1. Get your cloud ready.
  2. Set up your environment.
  3. Create an Yandex Object Storage bucket.
  4. Create a YDB database.
  5. Create Yandex Cloud Functions 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 in Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or register 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 navigate to the cloud page to create or select a folder for your infrastructure to operate in.

Learn more about clouds and folders.

Required paid resourcesRequired paid resources

The cost of resources to support a web application includes:

  • Fee for the number of requests to the API gateway and outbound 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 to a function, and outbound traffic (see Cloud Functions pricing).

Set up your environmentSet up your environment

  1. Create a service account and assign it the editor role for your folder.

  2. Clone the repository containing 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 Yandex Cloud Functions functions.

Create an Object Storage bucketCreate an Object Storage bucket

Create a bucket and upload index.html there:

Management console
  1. In the management console, select the folder where you want to create a bucket.
  2. Select Object Storage.
  3. Click Create bucket.
  4. On the bucket creation page:
    1. Enter a name for the bucket as per the naming requirements.
    2. Limit the maximum bucket size, if required.
    3. In the Object read access, Object listing access, and Read access to settings fields, select Restricted.
    4. Select the default storage class.
    5. Click Create bucket to complete the operation.
  5. Select the bucket you created.
  6. Click Upload and select the src/main/resources/index.html file in the project folder.
  7. Select the storage class for the file and click Upload.

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

  1. Create a database in serverless mode:

    Management console
    1. In the management console, select the folder where you created the bucket.

    2. Select Managed Service for YDB.

    3. Click Create a database.

    4. Enter the database Name. The naming requirements are as follows:

      • It must be from 2 to 63 characters long.
      • It may contain lowercase Latin letters, numbers, and hyphens.
      • It must start with a letter and cannot end with a hyphen.
    5. Under Database type, select Serverless.

    6. Click Create a database.

    7. Wait until the database starts. 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 database created.

    9. Under Connection, find the Endpoint field and save its value. You will need it when creating functions.

  2. Create a table named Tasks:

    Management console
    CLI
    1. In the management console, select the folder where you created the database.

    2. Select Managed Service for YDB.

    3. Select a database on the Databases page.

    4. To open the DB root directory, navigate to the Navigation tab.

    5. To make a query to the database, click New SQL query in the top-right corner. The Query page will open.

    6. In the Query field, enter:

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

    Run this request:

    ydb -e grpcs://<YDB_endpoint> -d <DB_name> \
    scripting yql -s \
    "CREATE TABLE Tasks
    (
      TaskId Utf8,
      Name Utf8,
      Description Utf8,
      CreatedAt Datetime,
      PRIMARY KEY (TaskId)
    );"
    

Create Cloud Functions functionsCreate Cloud Functions functions

Create a function for each servlet:

Management console
CLI
API
Yandex Cloud Toolkit
  1. In the management console, navigate to the folder where you created the bucket and database.
  2. Select Cloud Functions.
  3. Click Create function.
  4. Enter a name, e.g., add-task, and description for the function.
  5. Click Create.
  6. Under Editor, select the java21 runtime environment, disable Add files with code examples, and click Continue.
  7. Prepare the function code. To do this, select ZIP archive in the Method field.
  8. In the File field, click Attach file and select the servlet.zip archive 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, enter the account you created when setting up your environment.
  12. Add these environment variables:
    • ENDPOINT: Enter the first part of the Endpoint field value saved when creating the 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 saved when creating the YDB database (the one following /?database=), e.g., /ru-central1/r1gra875baom********/g5n22e7ejfr1********.
  13. Click Save changes.
  14. On the Overview page, enable Public function.
  15. Repeat steps 3-14 and create a function named list-tasks with the yandex.cloud.examples.serverless.todo.ListTasksServlet entry point.
  16. Repeat steps 3-14 and 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: d4ejb1799eko********
    folder_id: aoek49ghmknn********
    created_at: "2021-03-08T14:07:32.134Z"
    name: add-task
    log_group_id: eolm8aoq9vcp********
    http_invoke_url: https://functions.yandexcloud.net/d4ejb1799eko********
    status: ACTIVE
    
  2. Create a version of the add-task function:

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

    Where:

    • --function-name: Name of the function whose version you want to create.
    • --runtime: Runtime environment.
    • entrypoint: Entry point in <function_file_name>.<handler_name> format.
    • --memory: Amount of RAM.
    • --execution-timeout: Maximum running time of the function until timeout.
    • --source-path: Path to the previously created servlet.zip archive with the function code and required dependencies.
    • --environment: Environment variables in key=value format.

    Result:

    done (1s)
    id: d4evvn8obisa********
    function_id: d4ejb1799eko********
    ...
    tags:
    - $latest
    log_group_id: ckg3qh8h363p********
    
  3. Make the function public:

    yc serverless function allow-unauthenticated-invoke add-task
    

    Result:

    done (1s)
    
  4. Repeat steps 1-3 and create a function named list-tasks with the yandex.cloud.examples.serverless.todo.ListTasksServlet entry point.

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

Use the create, createVersion, and setAccessBindings API methods for the Function resource.

You can create a function and its version using the Yandex Cloud Toolkit plugin for the IDE family on the JetBrains IntelliJ platform.

Create an API gatewayCreate an API gateway

To ensure interaction between the services, create an API gateway:

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

  2. Select API Gateway.

  3. Click Create API gateway.

  4. Enter a name and description for the gateway.

  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>
            object: index.html
            presigned_redirect: false
            service_account: <service_account>
          operationId: static
      /add:
         post:
           x-yc-apigateway-integration:
             type: cloud-functions
             function_id: <add-task_ID>
           operationId: addTask
      /list:
        get:
          x-yc-apigateway-integration:
            type: cloud-functions
            function_id: <list-tasks_ID>
          operationId: listTasks
      /delete:
        delete:
          x-yc-apigateway-integration:
            type: cloud-functions
            function_id: <delete-task_ID>
          operationId: deleteTask
    

    Where:

    • bucket: Name of the bucket containing index.html.
    • service_account: 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.

  1. Save the following specification to the todo.yaml file:

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

    Where:

    • bucket: Name of the bucket containing index.html.
    • service_account: 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.
  2. Create an API gateway:

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

    Result:

    done (41s)
    id: d5delqeel34q********
    folder_id: b1g86q4m5vej********
    created_at: "2021-03-08T14:07:32.134Z"
    name: todo-list
    description: simple todo list
    status: ACTIVE
    domain: d5dm1lba80md********.i9******.apigw.yandexcloud.net
    log_group_id: ckg2hdmevnvc********
    

You can create an API gateway using the Yandex Cloud Toolkit plugin for the IDE family on the JetBrains IntelliJ platform.

Test the applicationTest the application

To open the app, follow the link in the Default domain field of the API gateway you created.

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

To stop paying for the resources you created:

  • Delete the bucket.
  • Delete the database.
  • Delete the functions.
  • Delete the API gateway.

Was the article helpful?

Previous
Creating an interactive serverless application using WebSocket
Next
Developing a Telegram bot
© 2025 Direct Cursus Technology L.L.C.