Skip to content

A template for creating a digital ocean serverless function.

License

Notifications You must be signed in to change notification settings

Zageron/digital-ocean-serverless-template

Repository files navigation

Digital Ocean - Serverless Template


Delete the Licence

Delete LICENCE.markdown before you start doing anything.


Setting up doctl

  • Install doctl manually, or via choco. choco install doctl
  • Authorize doctl. doctl auth init --context customname
  • Switch to the new identity context. doctl auth switch --context customname
  • Install the DigitalOcean sandbox: doctl sls install
  • Connect to your sandbox: doctl sandbox connect

Convert from Template to Function

  • Modify .do/deploy.template.yaml
    • Edit functions/github/repo to your desired repo user/repo.
    • Edit functions/name to your desired function name.
    • Edit name to your desired do function name.

For more details see App Specification Reference and How To - Manage Functions

Project.yml

  • In order to have the unmodified body be passed to your function, be sure to set the following in project.yml.
packages:
  - name: test-serverless
    actions:
      - name: test
        runtime: 'python:default'
        web: raw

Testing - Deploy to DO Function

If you have dependencies in any of the actions, you will need to implement build.<sh|cmd> scripts for your platform.

doctl sls deploy . --incremental

If you'd rather just implement different platform build scripts, then use the following command to keep to one.

doctl sls deploy . --remote-build

Environment Variables

If you have environment variables, add this flag to the deploy command. --env .env

Testing a deployed function via CLI

  • After the function has been successfully deployed, call doctl sbx fn get namespace/function --url to get the URL of your function.
  • Use wget <link> to activate a simple function.
  • Use doctl sls activations get to get the results of the most recent activation.

Watch

You may also use incremental directory watching to avoid having to run deployment automatically.

doctl sls watch .

Errors

Error: While deploying action 'some-service/action': Action is named in the config but does not exist in the project

This means that you've forgotten to rename the folder structures that your function lives in. Ex. packagtes/digitalocean-serverless/test.


Deploying to an App

  • Before you deploy to an app you'll need to make the build scripts executable if you haven't already. Run git update-index --chmod=+x path/to/build.ext for each of the builds scripts.

Renaming an App

Renaming Steps

  • Rename the function folder. packages/myservice/function -> packages/newservice/newfuncname
  • Update project.yml name fields.
  • Update .do/deploy.template.yaml name fields.

Execution Status

About

A template for creating a digital ocean serverless function.

Resources

License

Stars

Watchers

Forks