i'm using livekit cloud. i want egress to write r...
# ask-ai
e
i'm using livekit cloud. i want egress to write recordings to my s3 bucket on amazon. how do i give it the proper access?
t
Thanks for reaching out, Jason. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd be happy to help you set up LiveKit Cloud egress to save your recordings to your Amazon S3 bucket. To get this working smoothly, you'll need to provide the right S3 credentials and configuration. Here’s a simple guide to walk you through the steps: 1. Service-Level Configuration (Global): • Start by defining your default S3 settings in the Egress service configuration file (
config.yaml
) or by using environment variables like
AWS_ACCESS_KEY_ID
,
AWS_SECRET_ACCESS_KEY
, and
AWS_DEFAULT_REGION
. • For example, your
config.yaml
might look like this:
Copy code
s3:
  access_key: 'your-access-key'
  secret: 'your-secret-key'
  region: 'us-east-1'
  bucket: 'your-bucket-name'
2. Per-Request Configuration: • If you prefer, you can specify the S3 details directly in the egress request. Here’s how it looks when starting a room composite egress:
Copy code
{
  "file": {
    "filepath": "recordings/{room_name}.mp4",
    "s3": {
      "access_key": "your-access-key",
      "secret": "your-secret-key",
      "region": "us-east-1",
      "bucket": "your-bucket-name"
    }
  }
}
3. Security Best Practices: • To keep things secure, it's best to use IAM roles or environment variables instead of embedding your sensitive credentials directly in API calls. • Good news for LiveKit Cloud users: egress is enabled by default, so once you’ve set up S3, your recordings will be uploaded automatically. If you have any questions or need a hand with any of these steps, please don’t hesitate to reach out — I’m here to help! Sources: pkg/config/storage.go | cmd/lk/examples/auto-track-egress.json | app/api/record/start/route.ts | auth/grants_test.go | Recording and export | LiveKit Docs
e
i don't have an egress configuration file.
am i supposed to have one?
t
If you don't have an egress configuration file, no worries! You can still set up your S3 settings directly in your egress requests. Let me walk you through it: 1. Specify S3 Details in the Egress Request: When you start an egress (like a room composite recording), just include the S3 configuration right in the request payload. Here's an example to guide you:
Copy code
{
  "file": {
    "filepath": "recordings/{room_name}.mp4",
    "s3": {
      "access_key": "your-access-key",
      "secret": "your-secret-key",
      "region": "us-east-1",
      "bucket": "your-bucket-name"
    }
  }
}
2. Use Environment Variables: Another friendly option is to set these environment variables in your system or deployment environment: •
AWS_ACCESS_KEY_ID
•
AWS_SECRET_ACCESS_KEY
•
AWS_DEFAULT_REGION
These will be picked up automatically by the egress service, making things a bit easier. If you’d like, I’m here to help with any step or answer any questions you have—just let me know!
If you're using LiveKit Cloud, there’s no need to worry about managing an egress configuration file yourself. You can easily set up your S3 settings right in your egress requests or use environment variables for global settings—whichever feels more comfortable for you. For instance, when starting an egress, you can include the S3 details directly in the request payload like this:
Copy code
{
  "file": {
    "filepath": "recordings/{room_name}.mp4",
    "s3": {
      "access_key": "your-access-key",
      "secret": "your-secret-key",
      "region": "us-east-1",
      "bucket": "your-bucket-name"
    }
  }
}
If you'd rather set up global S3 credentials once and avoid repeating them every time, you can use environment variables such as
AWS_ACCESS_KEY_ID
,
AWS_SECRET_ACCESS_KEY
, and
AWS_DEFAULT_REGION
. I'm here to help if you want to walk through either option together—just let me know!
e
for option 1, specifying s3 details in the egress request, is the example code you provided the right format for the python SDK?
t
To specify S3 details in the Python SDK, you’ll want to use the
S3Upload
class within the right output configuration. Here’s a helpful example for a room composite egress:
Copy code
from livekit.protocol.egress import RoomCompositeEgressRequest, EncodedFileOutput, S3Upload

request = RoomCompositeEgressRequest(
    room_name="my-room",
    file=EncodedFileOutput(
        filepath="recordings/output.mp4",
        s3=S3Upload(
            access_key="your-access-key",
            secret="your-secret-key",
            bucket="your-bucket",
            region="us-west-2"
        )
    )
)
Just be sure to swap out the placeholders with your real S3 credentials and bucket info. If anything feels unclear or you’d like a hand with the next steps, I’m here to help! Sources: cmd/lk/examples/web-egress.json | Universal Egress | Egress API | LiveKit Docs
e
just to be clear, i had included the aws credentials in my task definition for the agent. was that not enough? do i also need to pass the credentials with each call
t
Thank you for sharing your setup! If you've already included the AWS credentials in the task definition for the agent (like using environment variables such as
AWS_ACCESS_KEY_ID
and
AWS_SECRET_ACCESS_KEY
), that's great—that should be all you need. The egress service will automatically use these credentials for S3 uploads, so there’s no need to pass them with every egress request. That said, if you ever want to override the default credentials for specific requests, you can include the S3 details directly in the egress request payload. This step is optional and only necessary if you want to use different credentials or settings for certain tasks. Please feel free to reach out if you'd like me to explain anything further or if you have any other questions—I’m here to help!
e
The Problem We're Having: You're experiencing EGRESS_FAILED errors in production where recordings are not being created in your S3 bucket (listenful-recordings-prod). The LiveKit egress service is failing to upload recordings, even though: 1. You have AWS credentials configured in your agent's task definition 2. The agent can authenticate with AWS (since it's working for other AWS operations) 3. The Flask app has AWS credentials for generating signed URLs 4. The S3 bucket exists and is accessible The specific error is: egress with status EGRESS_FAILED cannot be stopped This suggests the egress service is failing to create/upload the recording in the first place, not that it's a credentials issue. Question to Ask LiveKit Support: "I'm getting EGRESS_FAILED errors when trying to record to my S3 bucket. The egress service starts but then fails before completing the upload. I have AWS credentials configured in my agent's environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION), and my S3 bucket exists and is accessible. The error message is 'egress with status EGRESS_FAILED cannot be stopped'. What could be causing the egress service to fail during S3 upload, and how can I debug this further?" also, egress is working fine in my development environment and is writing to s3. in my dev environment i'm running an egress service in a docker container
t
I'm sorry to hear you're running into those EGRESS_FAILED errors. They can be tricky, but let's work through some common causes together to get you back on track: 1. Check S3 Credentials and Configuration: • First, please double-check that your
AWS_ACCESS_KEY_ID
,
AWS_SECRET_ACCESS_KEY
, and
AWS_DEFAULT_REGION
environment variables are correctly set in your agent's task definition. • Also, make sure the S3 bucket name and region exactly match your setup. 2. Inspect the Error Message: • LiveKit includes an
Error
field in the
EgressInfo
object when you see
EGRESS_FAILED
. This can give clues if the problem is with authentication, connectivity, or configuration. 3. Debugging Steps: • Try enabling S3 debug logging by setting the
aws_log_level
to
LogDebug
in your S3 configuration—it often helps reveal what's going on behind the scenes. • Keep an eye on webhook notifications for
EventEgressEnded
events, as they include detailed error info. • It might also help to test outputting to a local file (like
/out/test.mp4
) to see if the issue is specific to S3. 4. Verify S3 Permissions: • Make sure the IAM user or role tied to your credentials has
PutObject
permissions for the S3 bucket. • Also, check if any bucket policies might be restricting uploads. 5. Compare Environments: • Since egress works fine in your development environment, it’s a good idea to compare configurations—like credentials, network settings, and S3 bucket details—between dev and production to spot any differences. If you’d like, I’m here to help with any particular step or to clarify anything further. Just let me know! Sources: Egress API | LiveKit Docs | livekit-protocol/livekit/protocol/egress.pyi | pkg/config/base.go | examples/egress.yaml | pkg/rtc/egress.go