Yandex Cloud
Search
Contact UsGet started
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML Services
    • Business tools
  • 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
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Yandex API Gateway
  • Getting started
    • All tutorials
    • Deploying a web application using the Java Servlet API
    • Creating a skill for Alice and a website with authorization
    • Developing a Slack bot
    • Developing a Telegram bot
    • Developing a Telegram bot for text and audio recognition
    • Developing a custom integration
    • Developing CRUD APIs for movie services
    • Working with an API gateway via WebSocket
    • Creating an interactive serverless application using WebSocket
    • Building a CI/CD pipeline in GitLab with serverless products
    • Interactive debugging of Cloud Functions functions
    • Deploying a web app with JWT authorization in API Gateway and authentication in Firebase
    • Canary release of a Cloud Functions function
    • Using API Gateway to set up speech synthesis in Yandex SpeechKit
    • Running a containerized app in Yandex Serverless Containers
    • URL shortener
    • Ingesting data into storage systems
    • API Gateway protection with Smart Web Security
  • 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 Object Storage bucket
  • Create a database in Managed Service for YDB
  • Create Cloud 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 September 10, 2025
  • Getting started
    • Required paid resources
  • Set up your environment
  • Create an Object Storage bucket
  • Create a database in Managed Service for YDB
  • Create Cloud Functions
  • Create an API gateway
  • Test the application
  • How to delete the resources you created

Learn how to use serverless technology and Java Servlet API to create a simple web application for managing a task 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 navigate to the cloud page to create or select a folder for your infrastructure.

Learn more about clouds and folders here.

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 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 Yandex Cloud Functions.

Create an Object Storage bucketCreate an Object Storage bucket

Create a bucket and upload index.html into it:

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 src/main/resources/index.html in the project directory.
  7. Select the storage class for the file and click Upload.

Create a database in Managed Service for YDBCreate a database in Managed Service for YDB

  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. Specify a Name for the database. Follow these naming requirements:

      • It must be from 2 to 63 characters long.
      • It can only 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 created database.

    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 the database on the Databases page.

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

    5. To make a database query, 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 FunctionsCreate Cloud Functions

Create a function for each servlet:

Management console
CLI
API
  1. In the management console, navigate to the folder where you created the bucket and the 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 java21 as the runtime environment, disable Add files with code examples, and click Continue.
  7. Set up the function code. To do this, select ZIP archive in the Method 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, specify 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 your YDB (the one between grpcs:// and /?database=), e.g., ydb.serverless.yandexcloud.net:2135.
    • DATABASE: Enter the second part of the Endpoint field value you saved when creating your YDB (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 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: 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 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.

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

Create an API gatewayCreate an API gateway

To enable communication between the 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. 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 todo.yaml:

    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********
    

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
All tutorials
Next
Creating a skill for Alice and a website with authorization
© 2025 Direct Cursus Technology L.L.C.