CodexBloom - Programming Q&A Platform

OCI Functions: implementing Retrieving Environment Variables in Node.js Runtime

πŸ‘€ Views: 405 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-14
oci functions node.js JavaScript

I recently switched to I'm having a hard time understanding I've been banging my head against this for hours. I'm currently developing a serverless function using Oracle Cloud Infrastructure (OCI) Functions, specifically targeting the Node.js runtime (v14). I've defined several environment variables in my function configuration, but I'm working with an scenario where these variables are not being read correctly at runtime. Here’s the function code that attempts to access the environment variable: ```javascript const MY_ENV_VAR = process.env.MY_ENV_VAR; console.log('Environment Variable:', MY_ENV_VAR); exports.handler = async (event) => { return { statusCode: 200, body: JSON.stringify({ message: `Value: ${MY_ENV_VAR}` }) }; }; ``` Despite setting `MY_ENV_VAR` to `HelloWorld` in the OCI Functions console, when I invoke the function, the output is: ``` Environment Variable: undefined ``` I've tried a couple of different methods to troubleshoot this: 1. I confirmed that the environment variable is set in the function configuration by checking the OCI console and even tried using the `oci` CLI to retrieve the function configuration. 2. I also added debug logs to print all environment variables using `console.log(process.env);` but no custom variables showed up. I ensured that the deployment was successful and re-deployed the function a few times, but the behavior hasn’t changed. Is there something I'm missing in the configuration? Are there specific limitations or best practices when dealing with environment variables in OCI Functions that I should be aware of? My development environment is Linux. Is there a better approach? What are your experiences with this? Any pointers in the right direction? My team is using Javascript for this CLI tool. Any examples would be super helpful.