---
metadata:
  - name: generator
    content: Diplodoc Platform v5.70.0
alternate:
  - https://sourcecraft.dev/portal/docs/en/sourcecraft/tutorials/sourcecraft-sites-web-app.md
  - https://sourcecraft.dev/portal/docs/ru/sourcecraft/tutorials/sourcecraft-sites-web-app.md
  - href: https://sourcecraft.dev/portal/docs/en/sourcecraft/tutorials/sourcecraft-sites-web-app.md
    type: text/markdown
    title: Markdown version
  - href: https://sourcecraft.dev/portal/docs/en/llms.txt?revision=r22101122
    rel: describedby
title: Web application on SourceCraft Sites and Yandex Cloud Functions
description: In this tutorial, you will deploy a static website on SourceCraft Sites with a Cloud Functions and API Gateway backend using CI/CD.
---
> **Documentation Index:** Fetch the complete configuration index at https://sourcecraft.dev/portal/docs/en/llms.txt?revision=r22101122


<!-- source: en/_tutorials/serverless/sourcecraft-sites-web-app.md -->
# Web application on SourceCraft Sites and Yandex Cloud Functions

This guide demonstrates an example of deploying a simple web application using various services and tools:

- Frontend: Static website on [SourceCraft Sites](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/sites).
- Backend: [Yandex Cloud Functions](https://yandex.cloud/en/docs/functions/concepts/function) cloud function combined with a [Yandex API Gateway](https://yandex.cloud/en/docs/api-gateway/concepts/) gateway.
- Storing and working with code: [SourceCraft](https://sourcecraft.dev/portal/docs/en/) repository.
- Creating Yandex Cloud resources: [SourceCraft CI/CD](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/ci-cd) and [SourceCraft service connections](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/service-connections) to Yandex Cloud.

This web application is suitable for development and prototyping, or for a pet project. Advantages of this approach:

- There is no need to set up a virtual machine or a server for either the frontend or the backend.
- Free hosting on [SourceCraft Sites](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/sites) with HTTPS access (no need to upload your own TLS certificate).
- The [free tier](https://yandex.cloud/en/docs/billing/concepts/serverless-free-tier) for **Yandex Cloud Functions** and **Yandex API Gateway** allows you to use them at no cost under light workloads.
- Free access to SourceCraft features for working with code and CI/CD under the **SourceCraft Free** [pricing plan](https://sourcecraft.dev/portal/docs/en/sourcecraft/pricing#src-plans).

{% note info %}

A web application (website) is published based on files hosted in a public [repository](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/#repos) belonging to a public SourceCraft [organization](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/#org).

You can confirm ownership of a SourceCraft Sites website in [Yandex Webmaster](https://webmaster.yandex.ru). For more information, see [Questions about SourceCraft](https://sourcecraft.dev/portal/docs/en/sourcecraft/qa/sourcecraft-sites#verify-site-owner).

{% endnote %}

To create a web app:

1. [Get ready to work](#prepare).
1. [Clone](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/repo-clone) (`git clone https://git@git.sourcecraft.dev/examples/sourcecraft-sites-web-app.git`) or [fork](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/fork-work#create-fork) the [repository](https://sourcecraft.dev/examples/sourcecraft-sites-web-app) into your organization on SourceCraft.
1. [Create a service connection](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/service-connections) named `default-service-connection`.
1. [Manually run](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/run-workflow-manually) the `create-resources` workflow on the `master` branch.
1. [Test your application](#test).

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

## Getting started {#prepare}

1. 
1. Authenticate in SourceCraft on the service [home page](https://sourcecraft.dev) or [sign up](https://sourcecraft.dev/portal/docs/en/sourcecraft/quickstart#registration).

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

The cost of web application infrastructure support includes:
* Cost of using the gateway (see [Yandex API Gateway pricing](https://yandex.cloud/en/docs/api-gateway/pricing)).
* Cost of using a cloud function ([Yandex Cloud Functions pricing](https://yandex.cloud/en/docs/functions/pricing)).

## Testing the application {#test}

To open the application, navigate to the following URL in your browser: `https://<organization_slug>.sourcecraft.site/<repository_name>`. If everything was set up correctly, you will see an input field for a name and a button on the page that opens. Enter a name and click the button; a greeting line should then appear below.

## Deleting Yandex Cloud resources {#clear-out}

You can delete the resources (the gateway and the cloud function) using one of the following methods:

* Manually in the Yandex Cloud console ([delete the function](https://yandex.cloud/en/docs/functions/operations/function/function-delete), [delete the API gateway](https://yandex.cloud/en/docs/api-gateway/operations/api-gw-delete)).
* [Manually](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/run-workflow-manually) run the `delete-resources` workflow in the repository.

## Unpublishing a website {#delete}

To unpublish a website, simply perform one of the following actions:

* Making a repository or organization private.
* Removing the `.sourcecraft/sites.yaml` file from the repository's main branch.

## Useful links {#see-also}

[Connecting to a Managed Service for YDB database from a Python function in Yandex Cloud Functions](https://yandex.cloud/en/docs/tutorials/serverless/connect-from-cf)
<!-- endsource: en/_tutorials/serverless/sourcecraft-sites-web-app.md -->
