Question

How to trigger Functions from App Platform, and fetch the results?

I’m trying to implement functions on App Platform, but am struggling to hook up the various pieces to each other. I’m using Django on linux.

I followed this tutorial https://github.com/digitalocean/sample-functions-python-jokes and was able to run the function in its own namespace in Functions (unconnected to App Platform).

Then I tried to adapt it to my own, but needed to import environmental variables. I think you can’t do that from Functions, you have to add it as a resource on your app in App Platform itself, following this tutorial: https://docs.digitalocean.com/products/app-platform/how-to/manage-functions/. I got the function to build again, but can’t figure out how to trigger it.

image alt text
control panel settings

The url it shows in the control panel after build is joke/joke.

  • I tried going to <mydomain>/joke/joke and Django returned "404 Page Not Found". This is what they allege is the live function URL.
  • I went to <mydomain>/do-functions-sample-jokes/ and it returned "Incomplete web function path. The path must contain /$namespace/$package/$function, $package can be 'default'."
  • I tried <mydomain>/do-functions-sample-jokes/joke/joke/ and it returned “There was an error processing your request.”
  • I created a Django view that should spit out the json, and tried to fetch it from /joke/joke, and it doesn’t return anything except the html header
  • my app name is beyondyield1, maybe that’s my namespace? I tried both <mydomain>/beyondyield1/do-functions-sample-jokes/joke and <mydomain>/beyondyield1/do-functions-sample-jokes/joke/joke and Django still tries to intercept it, and returns a 404.

How do I trigger this function and fetch the results?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
December 28, 2023

Hi there,

Indeed, as you mentioned, to find the live URL of each function in your Function component, click to the Settings tab of your app and click the Function component you’d like to inspect:

I’ve just tested this and it seems to be working as expected on <mydomain>/joke/joke:

Do you by any chance have any custom routes defined that could be causing the issue?

Also, are you using the demo Jokes function or is it a custom one that you’ve built?

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel