Skip to content
Init is coming / May 19 - 23
Back

Cannot connect to localhost appwrite instance from function

  • 0
  • Self Hosted
  • Functions
kerimovscreations
26 Mar, 2025, 17:40

While I'm trying to access Appwrite Storage and Databases modules through Go client SDK receive an error like: http://localhost/v1/storage/buckets\": dial tcp [::1]:80: connect: connection refused

I have setup self-hosted Appwrite using Docker Desktop. All setup is fresh (2 days) and this is my first attempt to use Go client.

I have tried dynamic and standart API keys, both not worked.

I suspect there is a need for extra adjustments in network config in Docker.

Source code

TypeScript
Context.Log("Hello from Appwrite Function!")
    Context.Log(os.Getenv("APPWRITE_FUNCTION_API_ENDPOINT"))
    Context.Log(os.Getenv("APPWRITE_FUNCTION_PROJECT_ID"))
    Context.Log(os.Getenv("APPWRITE_FUNCTION_API_KEY"))
Context.Log(Context.Req.Headers["x-appwrite-key"])

client := appwrite.NewClient(
  appwrite.WithEndpoint(os.Getenv("APPWRITE_FUNCTION_API_ENDPOINT")),
  appwrite.WithProject(os.Getenv("APPWRITE_FUNCTION_PROJECT_ID")),
  appwrite.WithKey(Context.Req.Headers["x-appwrite-key"]),
  appwrite.WithSelfSigned(true),
)

storage := appwrite.NewStorage(client)

response, err := storage.ListBuckets()
if err != nil {
Context.Error(err)
return Context.Res.Text(err.Error(), Context.Res.WithStatusCode(500))
}

Context.Log(response)
TL;DR
Issue: Developer is unable to connect to the localhost Appwrite instance from the function using Go client SDK. Solution: The error "connection refused" indicates a network configuration issue in Docker. Ensure that the API endpoint, project ID, and API key are correctly set up in the environment variables and the client options.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more