I got this error message in egress from trying to ...
# ask-ai
m
I got this error message in egress from trying to save recording to S3 bucket:
S3 upload failed: operation error S3: PutObject, get identity: get credentials: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, http response error StatusCode: 404, request to EC2 IMDS failed
Here is my code block:
Copy code
req = api.RoomCompositeEgressRequest(
    room_name=ctx.room.name,
    audio_only=True,
    file_outputs=[api.EncodedFileOutput(
        file_type=api.EncodedFileType.OGG,
        filepath=f"recordings/{agent_name}/{ctx.room.name}_{current_date}.ogg",
        s3=api.S3Upload(
            bucket=AWS_BUCKET_NAME,
            region=AWS_REGION,
            access_key=os.getenv("AWS_ACCESS_KEY_ID"),
            secret=os.getenv("AWS_SECRET_ACCESS_KEY"),
        ),
    )],
)

lkapi = api.LiveKitAPI()
res = await lkapi.egress.start_room_composite_egress(req)
logger.info(f"[RECORDING] Recording started successfully: {res.egress_id}")
await lkapi.aclose()
t
Thanks for reaching out, Fancy. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It looks like the error is happening because the LiveKit egress service is trying to get AWS credentials through the EC2 Instance Metadata Service (IMDS), but there isn’t an IAM role attached to your EC2 instance. Don’t worry, we can work through this together! Here are a couple of ways to fix it: • Option 1: You can provide static AWS credentials (your access key and secret key) directly in the egress service configuration file under the
storage.s3
section, or set them as environment variables
AWS_ACCESS_KEY_ID
and
AWS_SECRET_ACCESS_KEY
. This works well if you’re not running on EC2 or if you’re not using IAM roles. • Option 2: If you are running on an EC2 instance, the best approach is to assign an IAM role with the right S3 permissions to that instance. Make sure the role allows actions like
PutObject
and
GetBucketLocation
on the bucket you’re targeting. Also, if you need to assume a different IAM role for your S3 uploads, you can specify the
assume_role_arn
in the egress request configuration, along with the necessary
access_key
and
secret
to perform the AssumeRole operation. If you have any questions or want me to walk you through any of these steps, just let me know—I’m here to help! Sources: go.sum | protobufs/livekit_egress.proto | go.sum
m
I've already provided aws credentials in the code:
Copy code
access_key=os.getenv("AWS_ACCESS_KEY_ID"),
secret=os.getenv("AWS_SECRET_ACCESS_KEY"),
Is that something I have to manually configure in Livekit Cloud UI?
t
Thank you for reaching out! I wanted to let you know that AWS credentials for S3 uploads in egress are configured per request, so there’s no need to manually set them in the LiveKit Cloud UI. I see that in your code, you’re already passing the credentials in the egress request configuration:
Copy code
access_key=os.getenv("AWS_ACCESS_KEY_ID"),
secret=os.getenv("AWS_SECRET_ACCESS_KEY"),
Just a quick tip: please make sure that the environment variables
AWS_ACCESS_KEY_ID
and
AWS_SECRET_ACCESS_KEY
are correctly set and accessible in the environment where your code runs. If you’re still running into issues, it might help to double-check that the credentials have the right permissions for S3 operations like
PutObject
and
GetBucketLocation
on your target bucket. I’m here if you need any more help! Sources: Web Egress | LiveKit Docs | Egress API | LiveKit docs