[SOLVED] Function throws ECONNREFUSED when running local container
- 0
- Self Hosted
- Functions
- Locale
Hosting Appwrite on local docker container (http://localhost:80). Mocha test calls to Appwrite storage works correctly. Deployed function anyway does not connect to storage. Causes Exception: connect ECONNREFUSED 127.0.0.1:80 when running row "const fileInfo = await storage.getFile(bucketId, fileId);". Seems like function instance do not see appwrite container instance althought should be in same docker-compose network I suppose. Like said same code runs and connect to appwrite without any problems when used in mocha test. I assume this to be some env setup problem. Below envs related to functions. _APP_FUNCTIONS_SIZE_LIMIT=30000000 _APP_FUNCTIONS_TIMEOUT=900 _APP_FUNCTIONS_BUILD_TIMEOUT=900 _APP_FUNCTIONS_CONTAINERS=10 _APP_FUNCTIONS_CPUS=0 _APP_FUNCTIONS_MEMORY=0 _APP_FUNCTIONS_MEMORY_SWAP=0 _APP_FUNCTIONS_RUNTIMES=node-18.0,dotnet-6.0,python-3.9 _APP_EXECUTOR_SECRET=your-secret-key _APP_EXECUTOR_HOST=http://appwrite-executor/v1 _APP_EXECUTOR_RUNTIME_NETWORK=appwrite_runtimes _APP_FUNCTIONS_ENVS=node-18.0,dotnet-6.0,python-3.9 _APP_FUNCTIONS_INACTIVE_THRESHOLD=60
Should I set here some env like function endpoint?
The function endpoint is basically the endpoint of your appwrite instance. Would you be able to share some code to see if maybe there was a human-error?
import * as sdk from 'node-appwrite' import { createWriteStream, existsSync, mkdir } from 'fs' import { Readable } from 'stream'
let client: any; let storage: any;
const DOWNLOADS_FOLDER = ./downloads
;
function setup(){
try{
if(typeof process.env.APPWRITE_PROJECT_ID === 'undefined') throw Error(process.env.APPWRITE_PROJECT_ID not defined...
)
if(typeof process.env.APPWRITE_ENDPOINT === 'undefined') throw Error (process.env.APPWRITE_ENDPOINT not defined...
);
if(typeof process.env.APPWRITE_API_KEY === 'undefined') throw Error (process.env.APPWRITE_API_KEY not defined...
);
client = new sdk.Client()
client
.setEndpoint(process.env.APPWRITE_ENDPOINT)
.setProject(process.env.APPWRITE_PROJECT_ID)
.setKey(process.env.APPWRITE_API_KEY)
// .setSelfSigned() // Use only on dev mo
// databases = new sdk.Databases(client);
storage = new sdk.Storage(client);
if(typeof client === 'undefined') throw Error (`client not defined...`);
// if(typeof databases === 'undefined') throw Error (`databases not defined...`);
if(typeof storage === 'undefined') throw Error (`storage not defined...`);
console.log(`Appwrite setup done...`);
}catch(e: any){ console.log(e.message); } }
Calling storage fails ....const fileInfo = await storage.getFile(bucketId, fileId);
I was thinking this // .setSelfSigned() // Use only on dev mo...will that cause an issue?
Just a tip - use 3 backticks ( ` ) at the start and end of your code to format it. Makes it much easier to read <:appwritepeepo:902865250427215882>
APPWRITE_ENDPOINT
what's the value for this env variable?
APPWRITE_ENDPOINT=http://localhost/v1
Running mocha tests locally works without any problems. I have these connection issue only when running deployed function.
This is log from deployed function
You can't use localhost in a function because the function will try to connect to itself rather than Appwrite. Use your LAN IP instead.
Thanks, this solved the problem. A little bit confusing forced to use IP when using docker-compose.yaml file for deployment. Normally different instances uses network names to find each others. Anyway works now ...I appreciate your help!
[SOLVED] Function throws ECONNREFUSED when running local container
Yes, but for security reasons, the runtime container is on a separate docker network so it doesn't have access to the appwrite container
Recommended threads
- Realtime with multiple connections
I need the Realtime on multiple Collections for diffrent applicational logic. So my question is: Is there a way to have only 1 Websocket connection or do I need...
- Can't login or deploy functions in Appwr...
Hello, since i updatet to the appwrite cli 6.1.0 i can't login or deploy functions with the cli. When i call the command: "appwrite get account --verbose" i ge...
- Create admin user?
I'm not really sure how this is supposed to work, I installed Appwrite through docker-compose and set it up. When I launched the app and went into it, I created...