{"id":483262,"date":"2022-08-11T01:00:17","date_gmt":"2022-08-10T22:00:17","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-get-started-with-digitaloceans-serverless-functions\/"},"modified":"2022-08-11T01:00:17","modified_gmt":"2022-08-10T22:00:17","slug":"how-to-get-started-with-digitaloceans-serverless-functions","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-with-digitaloceans-serverless-functions\/","title":{"rendered":"#How to Get Started With DigitalOcean\u2019s Serverless Functions"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a3cd140b4ce6\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a3cd140b4ce6\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-with-digitaloceans-serverless-functions\/#%E2%80%9CHow_to_Get_Started_With_DigitalOceans_Serverless_Functions%E2%80%9D\" >&#8220;How to Get Started With DigitalOcean\u2019s Serverless Functions&#8221;<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-with-digitaloceans-serverless-functions\/#Supported_Features\" >Supported Features<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-with-digitaloceans-serverless-functions\/#Getting_Set_Up\" >Getting Set Up<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-with-digitaloceans-serverless-functions\/#Creating_a_Function\" >Creating a Function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-with-digitaloceans-serverless-functions\/#Invoking_and_Deploying_Functions\" >Invoking and Deploying Functions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-with-digitaloceans-serverless-functions\/#Modifying_Your_Function\" >Modifying Your Function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-with-digitaloceans-serverless-functions\/#Deploying_to_Production\" >Deploying to Production<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-get-started-with-digitaloceans-serverless-functions\/#Summary\" >Summary<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E2%80%9CHow_to_Get_Started_With_DigitalOceans_Serverless_Functions%E2%80%9D\"><\/span>&#8220;How to Get Started With DigitalOcean\u2019s Serverless Functions&#8221;<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<div>\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage alignnone size-full wp-image-810398\" data-pagespeed-no-defer=\"\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/06\/DigitalOcean.jpeg?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Graphic showing the DigitalOcean logo\" width=\"1600\" height=\"900\"\/><\/p>\n<p>Functions is one of the newest additions to the DigitalOcean cloud platform. It provides a first-class method for developing serverless functions without leaving DigitalOcean. Your code\u2019s executed on-demand when it\u2019s called, eliminating manual server provisioning and maintenance.<\/p>\n<p>In this article we\u2019ll explain what DigitalOcean Functions supports and walkthrough a demonstration of creating your own simple function. Functions has <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.digitalocean.com\/products\/functions\/details\/pricing\">a free tier<\/a> that provides 25 GiB-hours per month, with a GiB-second calculated as the memory consumption multiplied by the execution time of each function call.<\/p>\n<h2 id=\"supported-features\"><span class=\"ez-toc-section\" id=\"Supported_Features\"><\/span>Supported Features<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Launched in <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.digitalocean.com\/blog\/introducing-digitalocean-functions-serverless-computing\">May 2022<\/a>, Functions gives DigitalOcean customers a built-in option for running serverless workloads. Each function gets its own API endpoint that runs the code you\u2019ve created. You don\u2019t have to set up your own servers or containerize the project before deployment. Live functions are hosted by DigitalOcean\u2019s <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">App<\/a> Platform backend.<\/p>\n<p>Functions can integrate with DigitalOcean\u2019s Managed Databases to facilitate persistent data storage. They also come with a comprehensive CLI that lets you deploy and test your code in your terminal.<\/p>\n<p>The initial version of the platform supports five different programming environments:<\/p>\n<ul>\n<li>Go 1.17<\/li>\n<li>Node.js 14<\/li>\n<li>Node.js 14 (compatible with AWS Lambda functions)<\/li>\n<li>PHP 8<\/li>\n<li>Python 3.9<\/li>\n<\/ul>\n<p>You\u2019ll need to be comfortable writing your code in one of these languages to deploy it as a function. More runtimes could be supported in the future.<\/p>\n<h2 id=\"getting-set-up\"><span class=\"ez-toc-section\" id=\"Getting_Set_Up\"><\/span>Getting Set Up<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>It\u2019s possible to launch new functions using DigitalOcean\u2019s web control panel or Doctl, its developer-oriented CLI. We\u2019re focusing on the terminal-based Doctl approach for the purposes of this article. This exposes all the capabilities of Functions and <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.digitalocean.com\/products\/functions\/quickstart\">is the intended pathway<\/a> for all but the simplest use cases. Make sure you\u2019ve got the latest version of Doctl installed and authenticated to your DigitalOcean account before you continue.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-810400\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-09-at-14-55-26-DigitalOcean.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"image of DigitalOcean Functions\" width=\"1280\" height=\"648\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You\u2019ll need to complete some further set up steps if this is the first time you\u2019re using DigitalOcean Functions. First finish the installation of Doctl\u2019s <code>serverless<\/code> extension. This adds full support for developing and deploying functions.<\/p>\n<pre>$ doctl serverless install&#13;\nDownloading...Unpacking...Installing...Cleaning up...&#13;\nDone<\/pre>\n<p>Next connect the serverless features to your DigitalOcean account:<\/p>\n<pre>$ doctl serverless connect&#13;\nConnected to function namespace 'fn-3c1d9001-8e04-44e8-9375-c22b13c4a41a' on API host 'https:\/\/faas-lon1-917a94a7.doserverless.co'<\/pre>\n<p>Now you should be ready to start writing functions. Run the <code>serverless status<\/code> command to check everything\u2019s working:<\/p>\n<pre>$ doctl serverless status&#13;\nConnected to function namespace 'fn-3c1d9001-8e04-44e8-9375-c22b13c4a41a' on API host 'https:\/\/faas-lon1-917a94a7.doserverless.co'&#13;\nSandbox version is 3.1.1-1.2.1<\/pre>\n<p>The output shown above confirms Functions support is installed and ready to use.<\/p>\n<p>The <code>serverless<\/code> command is an alias of <code>sandbox<\/code>. At the time of writing, the two keywords have identical functionality and are used interchangeably across DigitalOcean\u2019s documentation. We\u2019re standardizing on <code>serverless<\/code> for this guide.<\/p>\n<h2 id=\"creating-a-function\"><span class=\"ez-toc-section\" id=\"Creating_a_Function\"><\/span>Creating a Function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Use the following command to create a new Functions project:<\/p>\n<pre>$ doctl serverless init --language js demo-project&#13;\nA local sandbox area 'demo-project' was created for you.&#13;\nYou may deploy it by running the command shown on the next line:&#13;\n  doctl sandbox deploy demo-project<\/pre>\n<p>This command creates a new JavaScript function within <code>demo-project<\/code> in your working directory. Inspect the contents of this directory to see what Doctl has scaffolded for you:<\/p>\n<pre>$ tree demo-project&#13;\ndemo-project&#13;\n\u251c\u2500\u2500 packages&#13;\n\u2502   \u2514\u2500\u2500 sample&#13;\n\u2502       \u2514\u2500\u2500 hello&#13;\n\u2502           \u2514\u2500\u2500 hello.js&#13;\n\u2514\u2500\u2500 project.yml&#13;\n&#13;\n3 directories, 2 files<\/pre>\n<p>The <code>project.yml<\/code> file is where you configure your functions project and the endpoints it provides.<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"yaml\">\n<pre class=\"de1\"><span class=\"co3\">targetNamespace<\/span><span class=\"sy2\">: <\/span>''<span class=\"co3\">\nparameters<\/span><span class=\"sy2\">: <\/span><span class=\"br0\">{<\/span><span class=\"br0\">}<\/span><span class=\"co4\">\npackages<\/span>:<span class=\"co3\">\n  - name<\/span><span class=\"sy2\">: <\/span>sample<span class=\"co3\">\n    environment<\/span><span class=\"sy2\">: <\/span><span class=\"br0\">{<\/span><span class=\"br0\">}<\/span><span class=\"co3\">\n    parameters<\/span><span class=\"sy2\">: <\/span><span class=\"br0\">{<\/span><span class=\"br0\">}<\/span><span class=\"co3\">\n    annotations<\/span><span class=\"sy2\">: <\/span><span class=\"br0\">{<\/span><span class=\"br0\">}<\/span><span class=\"co4\">\n    actions<\/span>:<span class=\"co3\">\n      - name<\/span><span class=\"sy2\">: <\/span>hello<span class=\"co3\">\n        binary<\/span><span class=\"sy2\">: <\/span>false<span class=\"co3\">\n        main<\/span><span class=\"sy2\">: <\/span>''<span class=\"co3\">\n        runtime<\/span><span class=\"sy2\">: <\/span>'nodejs:default'<span class=\"co3\">\n        web<\/span><span class=\"sy2\">: <\/span>true<span class=\"co3\">\n        parameters<\/span><span class=\"sy2\">: <\/span><span class=\"br0\">{<\/span><span class=\"br0\">}<\/span><span class=\"co3\">\n        environment<\/span><span class=\"sy2\">: <\/span><span class=\"br0\">{<\/span><span class=\"br0\">}<\/span><span class=\"co3\">\n        annotations<\/span><span class=\"sy2\">: <\/span><span class=\"br0\">{<\/span><span class=\"br0\">}<\/span><span class=\"co3\">\n        limits<\/span><span class=\"sy2\">: <\/span><span class=\"br0\">{<\/span><span class=\"br0\">}<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>The starter template configures one package called <code>sample<\/code>. Within this package, there\u2019s a single action (endpoint) named <code>hello<\/code> that\u2019s executed using the Node runtime. The source code for this action is stored at <code>packages\/sample\/hello\/hello.js<\/code>. Let\u2019s look at this file next:<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"javascript\">\n<pre class=\"de1\"><span class=\"kw1\">function<\/span> main<span class=\"br0\">(<\/span>args<span class=\"br0\">)<\/span> <span class=\"br0\">{<\/span>\n    let name <span class=\"sy0\">=<\/span> args.<span class=\"me1\">name<\/span> <span class=\"sy0\">||<\/span> <span class=\"st0\">'stranger'<\/span>\n    let greeting <span class=\"sy0\">=<\/span> <span class=\"st0\">'Hello '<\/span> <span class=\"sy0\">+<\/span> name <span class=\"sy0\">+<\/span> <span class=\"st0\">'!'<\/span>\n    console.<span class=\"me1\">log<\/span><span class=\"br0\">(<\/span>greeting<span class=\"br0\">)<\/span>\n    <span class=\"kw1\">return<\/span> <span class=\"br0\">{<\/span><span class=\"st0\">\"body\"<\/span><span class=\"sy0\">:<\/span> greeting<span class=\"br0\">}<\/span>\n<span class=\"br0\">}<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>This is regular JavaScript code. The <code>main()<\/code> function will be invoked each time your function\u2019s called. It receives an object containing arguments submitted as HTTP GET and POST data in the user\u2019s request. You can configure static arguments too, using the <code>parameters<\/code> field on actions, packages, and the top-level project in your <code>project.yml<\/code> file.<\/p>\n<p>Functions need to return an object that describes the HTTP response to issue. The <code>body<\/code> field becomes the data included in the response.<\/p>\n<h2 id=\"invoking-and-deploying-functions\"><span class=\"ez-toc-section\" id=\"Invoking_and_Deploying_Functions\"><\/span>Invoking and Deploying Functions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>This project is ready to run. Use this command to deploy your function:<\/p>\n<pre>$ doctl serverless deploy .&#13;\nDeploying '\/home\/james\/@scratch\/demo-project'&#13;\n  to namespace 'fn-3c1d9001-8e04-44e8-9375-c22b13c4a41a'&#13;\n  on host 'https:\/\/faas-lon1-917a94a7.doserverless.co'&#13;\nDeployment status recorded in '.nimbella'&#13;\n&#13;\nDeployed functions ('doctl sbx fn get &lt;funcName&gt; --url' for URL):&#13;\n  - sample\/hello<\/pre>\n<p>The <code>serverless deploy<\/code> command takes one argument, the path to the directory that contains your functions. Use <code>.<\/code> when the root of your project is already your working directory.<\/p>\n<p>Now you can test your function using the CLI:<\/p>\n<pre>$ doctl serverless functions invoke sample\/hello -p name:howtogeek&#13;\n{&#13;\n    \"body\": \"Hello howtogeek!\"&#13;\n}<\/pre>\n<p>The <code>-p<\/code> parameter sets an argument that\u2019s passed through to your code. This example demonstrates how your function\u2019s return value becomes the HTTP response body.<\/p>\n<p>Next try making a real API request to your function. You can discover its URL with the following command:<\/p>\n<pre>$ URL=$(doctl serverless functions get sample\/hello --url)<\/pre>\n<p>Use <code>curl<\/code> or your own favorite HTTP client to hit this endpoint:<\/p>\n<pre>$ curl $URL?name=howtogeek&#13;\nHello howtogeek!<\/pre>\n<p>The <code>name<\/code> query string parameter has been successfully passed through to the function.<\/p>\n<h2 id=\"modifying-your-function\"><span class=\"ez-toc-section\" id=\"Modifying_Your_Function\"><\/span>Modifying Your Function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>So far we\u2019re using DigitalOcean\u2019s sample code without any modification. This isn\u2019t going to take you far on your serverless journey! Edit your <code>hello.js<\/code> file so it looks like this:<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"javascript\">\n<pre class=\"de1\"><span class=\"kw1\">function<\/span> main<span class=\"br0\">(<\/span>args<span class=\"br0\">)<\/span> <span class=\"br0\">{<\/span>\n    <span class=\"kw1\">return<\/span> <span class=\"br0\">{<\/span>\n        body<span class=\"sy0\">:<\/span> <span class=\"br0\">{<\/span>\n            value<span class=\"sy0\">:<\/span> <span class=\"br0\">(<\/span>args.<span class=\"me1\">value<\/span> <span class=\"sy0\">*<\/span> <span class=\"nu0\">2<\/span><span class=\"br0\">)<\/span><span class=\"sy0\">,<\/span>\n            timestamp<span class=\"sy0\">:<\/span> <span class=\"kw4\">Date<\/span>.<span class=\"me1\">now<\/span><span class=\"br0\">(<\/span><span class=\"br0\">)<\/span>\n        <span class=\"br0\">}<\/span><span class=\"sy0\">,<\/span>\n        headers<span class=\"sy0\">:<\/span> <span class=\"br0\">{<\/span>\n            <span class=\"st0\">\"Content-Type\"<\/span><span class=\"sy0\">:<\/span> <span class=\"st0\">\"application\/json\"<\/span>\n        <span class=\"br0\">}<\/span>\n    <span class=\"br0\">}<\/span><span class=\"sy0\">;<\/span>\n<span class=\"br0\">}<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>Re-deploy your function:<\/p>\n<pre>$ doctl serverless deploy .<\/pre>\n<p>This function naively doubles the number given by the <code>value<\/code> request parameter. It also includes a timestamp with each response body. The <code>headers<\/code> field is used in the response object to apply a correct JSON <code>Content-Type<\/code>.<\/p>\n<p>You can call this function using Doctl or <code>curl<\/code> in the same style as earlier:<\/p>\n<pre>$ curl $URL?value=2&#13;\n{&#13;\n  \"timestamp\": 1654784122966,&#13;\n  \"value\": 4&#13;\n}<\/pre>\n<p>Manually re-deploying your function after each change is tedious and time-consuming. Run the <code>watch<\/code> command while you work to automatically deploy changes after you modify your files:<\/p>\n<pre>$ doctl serverless watch .&#13;\nWatching '.' [use Control-C to terminate]<\/pre>\n<p>Keep the terminal window open as you develop your function. Each new deployment will log a message so you know when you can test your changes. This facilitates efficient iteration as you develop your functions.<\/p>\n<p>You can stream logs from your functions too. This is invaluable when a function crashes or doesn\u2019t behave as you expected. Run this command to access the logs associated with your demo function:<\/p>\n<pre>$ doctl serverless activations logs --follow --function sample\/hello<\/pre>\n<p>A new line will be printed each time you call your function. The logs also include messages that your code emits to the environment\u2019s standard output and error streams.<\/p>\n<h2 id=\"deploying-to-production\"><span class=\"ez-toc-section\" id=\"Deploying_to_Production\"><\/span>Deploying to Production<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <code>serverless deploy<\/code> command is currently <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.digitalocean.com\/products\/functions\/how-to\/deploy-to-production\">designed for development use<\/a> only. You can deploy to production by creating a Git repository for your Functions project and launching it using DigitalOcean\u2019s App Platform.<\/p>\n<p>Create a new project on GitHub or GitLab and push up your code:<\/p>\n<pre>$ git init&#13;\n$ git remote add origin git@github.com:user\/repo.git&#13;\n$ git add .&#13;\n$ git commit -m \"initial commit\"&#13;\n$ git push -u origin master<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-810401\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-09-at-15-39-46-DigitalOcean-App-Platform.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"image of creating an app in DigitalOcean App Platform\" width=\"1280\" height=\"648\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Next head to your DigitalOcean control panel and click the \u201cApps\u201d link in the left sidebar. Click the \u201cCreate App\u201d button that appears. On the next screen, follow the prompts to connect to your GitHub account and select your new repository. Press the blue \u201cNext\u201d button.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-810402\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-09-at-15-42-49-DigitalOcean-App-Platform.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"image of creating an app in DigitalOcean App Platform\" width=\"1280\" height=\"648\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>DigitalOcean will automatically detect your repository as a Functions project if you\u2019ve got a <code>project.yml<\/code> at its root. Click the \u201cSkip to Review\u201d button to continue.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-810403\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-09-at-15-44-13-DigitalOcean-App-Platform.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"image of a Functions app in DigitalOcean App Platform\" width=\"1280\" height=\"648\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>The next screen should confirm you\u2019ll be billed using the Functions plan.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-810404\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-09-at-15-45-21-DigitalOcean-App-Platform.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"image of a Functions app in DigitalOcean App Platform\" width=\"1280\" height=\"648\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Press \u201cCreate Resources\u201d to provision your app and start its first deployment. Progress will be shown on the dashboard.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-810405\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-09-at-15-45-38-sea-lion-app-DigitalOcean-App-Platform.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"image of a Functions app being deployed in DigitalOcean App Platform\" width=\"1280\" height=\"648\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>\u00a0<\/p>\n<p>Your function\u2019s endpoints will be publicly accessible once the deployment completes. You can find your app\u2019s default <code>ondigitalocean.app<\/code> domain by scrolling down the App Settings page in your dashboard. In our example, the app\u2019s domain is <code>sea-lion-app.7ougx.ondigitalocean.app<\/code>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-810406\" data-pagespeed-lazy-src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/06\/Screenshot-2022-06-09-at-15-53-05-sea-lion-app-DigitalOcean-App-Platform.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"image of finding an app's domain in DigitalOcean App Platform\" width=\"1280\" height=\"648\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Functions are automatically exposed as URIs that have the following format:<\/p>\n<pre>&lt;app&gt;.ondigitalocean.app\/&lt;function-package&gt;\/&lt;function-action&gt;<\/pre>\n<p>You can invoke the sample function created earlier by making the following request:<\/p>\n<pre>$ curl https:\/\/sea-lion-app.7ougx.ondigitalocean.app\/sample\/hello?value=2&#13;\n{&#13;\n  \"timestamp\": 1654786505969,&#13;\n  \"value\": 4&#13;\n}<\/pre>\n<p>The function\u2019s been successfully deployed! You can now use the Domains tab in your app\u2019s settings to attach a custom domain instead of the default one.<\/p>\n<h2 id=\"summary\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>DigitalOcean Functions is the newest competitor in the increasingly crowded serverless functions arena. The platform lets you develop server-side functionality without managing VMs or manually containerizing your code.<\/p>\n<p>Functions provides a comprehensive CLI for building and testing your endpoints. You can then deploy your functions to DigitalOcean\u2019s existing App Platform solution, either as a standalone project or as part of a larger app.<\/p>\n<p>Once you\u2019ve got a basic function operational, you can refer to <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.digitalocean.com\/products\/functions\/reference\/project-configuration\">DigitalOcean\u2019s documentation<\/a> to start configuring more advanced behaviors. You can set up environment variables, multiple actions, and resource limits using the fields in your <code>project.yml<\/code> file, giving you a quick and easy route to build relatively complex on-demand endpoints.<\/p>\n<\/div>\n<p><script>\n setTimeout(function(){\n  !function(f,b,e,v,n,t,s)\n  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?\n  n.callMethod.apply(n,arguments):n.queue.push(arguments)};\n  if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';\n  n.queue=[];t=b.createElement(e);t.async=!0;\n  t.src=v;s=b.getElementsByTagName(e)[0];\n  s.parentNode.insertBefore(t,s) } (window, document,'script',\n  'https:\/\/connect.facebook.net\/en_US\/fbevents.js');\n   fbq('init', '335401813750447');\n   fbq('track', 'PageView');\n  },3000);\n<\/script><\/p>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.howtogeek.com\/devops\/how-to-get-started-with-digitaloceans-serverless-functions\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;How to Get Started With DigitalOcean\u2019s Serverless Functions&#8221; Functions is one of the newest additions to the DigitalOcean cloud platform. It provides a first-class method for developing serverless functions without leaving DigitalOcean. Your code\u2019s executed on-demand when it\u2019s called, eliminating manual server provisioning and maintenance. In this article we\u2019ll explain what DigitalOcean Functions supports and&#8230;<\/p>\n","protected":false},"author":1,"featured_media":483263,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/06\/DigitalOcean.jpeg?height=200p&trim=2,2,2,2","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-483262","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/483262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=483262"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/483262\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/483263"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=483262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=483262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=483262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}