How to use custom env variables process.env.AWS_R...
# ask-ai
f
How to use custom env variables process.env.AWS_REGION in livekit agent
t
Thanks for reaching out, Munkhbaysgalan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Could you help me understand a bit better? Are you asking about how to set custom environment variables like process.env.AWS_REGION, how to access them in your LiveKit agent code, or how to configure them in a specific environment? I’m here to help with whichever you need!
f
use how to access them in agent code
const s3 = new S3Client({
region: process.env.AWS_REGION!, credentials: { accessKeyId: process.env.AWS_ACCESS_KEY_ID!, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!, }, }); export default defineAgent({ entry: async (ctx: JobContext) => { console.log('process.env.AWS_ACCESS_KEY_ID', process.env.AWS_ACCESS_KEY_ID!); i am using like this but stil cannot acces this secrets
t
Hey there! To access environment variables like
process.env.AWS_REGION
in your LiveKit agent code, here’s what you’ll want to do: 1. Make sure you’ve defined the necessary environment variables (
AWS_REGION
,
AWS_ACCESS_KEY_ID
,
AWS_SECRET_ACCESS_KEY
) either in a
.env
file or directly in your deployment environment. 2. If you’re working locally, a handy package like
dotenv
can load those variables from your
.env
file. Just run
npm install dotenv
and add
require('dotenv').config()
at the very top of your script. 3. Don’t forget to check that your deployment platform (like Render or AWS Lambda) is set up to pass these environment variables to your runtime environment. Here’s an example of what your
.env
file might look like:
Copy code
LIVEKIT_URL=your-livekit-url
LIVEKIT_API_KEY=your-api-key
LIVEKIT_API_SECRET=your-api-secret
AWS_ACCESS_KEY_ID=your-aws-key
AWS_SECRET_ACCESS_KEY=your-aws-secret
AWS_REGION=us-west-2
And in your code, make sure you’re referencing the variables like this:
Copy code
const s3 = new S3Client({
  region: process.env.AWS_REGION,
  credentials: {
    accessKeyId: process.env.AWS_ACCESS_KEY_ID,
    secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
  },
});

console.log('AWS Access Key:', process.env.AWS_ACCESS_KEY_ID);
If you’re still seeing those variables as undefined, it’s a good idea to double-check that they’re properly set and accessible to the process running your LiveKit agent. Feel free to reach out if you need a hand with this! Sources: complex-agents/nova-sonic/README.md | Transcription Applications | livekit/livekit_composite | DeepWiki | render/render.yaml | Example Applications | livekit/livekit_composite | DeepWiki | Amazon Transcribe STT integration guide | LiveKit Docs
f
dotenv.config({ path: '.env.local' }); class Assistant extends voice.Agent { constructor() { super({ instructions: 'You are Batbayar, a native Mongolian speaker from Ulaanbaatar, Mongolia who works as an English-language tutor in Mongolia. You will teach English to a beginner who is a native Mongolian speaker. You must conduct the majority of your lesson in Mongolian, since they are just a beginner. You have an accent which is characteristic of a native Mongolian speaker when speaking English.', }); } } const s3 = new S3Client({ region: process.env.AWS_REGION!, credentials: { accessKeyId: process.env.AWS_ACCESS_KEY_ID!, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!, }, }); export default defineAgent({ entry: async (ctx: JobContext) => { console.log('process.env.AWS_ACCESS_KEY_ID', process.env.AWS_ACCESS_KEY_ID); still can not access it why ?
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!