does the livekit only provide aws user access key ...
# ask-ai
c
does the livekit only provide aws user access key and secret based authentication for egress.. Or is there any way to do it using IAM Role too?
t
Thanks for reaching out, Divyanshu. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi there! I wanted to share that LiveKit supports both AWS access key/secret-based authentication and IAM Role-based authentication for egress, giving you flexible options to choose from. If you'd like to use IAM Role-based authentication, you can simply configure the
assume_role_arn
field in your S3 upload settings. This lets LiveKit assume a specific role through the AssumeRole API. To add an extra layer of security, you can also include the
assume_role_external_id
parameter for verification. Here’s a quick example of how your configuration might look:
Copy code
storage:
  s3:
    assume_role_arn: "arn:aws:iam::123456789012:role/LiveKitEgressRole"
    assume_role_external_id: "your-external-id"  # optional, if required by your role
    region: ""  # leave empty to use IAM role
    bucket: "your-bucket-name"
Just a heads-up: on LiveKit Cloud, IAM Role-based authentication is available only if this feature has been enabled for your account. If you’d like, I’m here to help you with this setup or answer any questions you might have! Sources: livekit/livekit_egress.pb.go | pkg/config/base.go
c
so how can i do that here async def start_recording_of_session_to_s3_via_egress( ctx: JobContext, lkapi: api.LiveKitAPI, ) -> api.EgressInfo: try: # Start S3 recording req = api.RoomCompositeEgressRequest( room_name=ctx.room.name, layout="speaker", preset=api.EncodingOptionsPreset.H264_720P_30, audio_only=False, file_outputs=[ api.EncodedFileOutput( file_type=api.EncodedFileType.MP4, filepath="livekit-poc-data/recordings/recording-{room_name}-{time}.mp4", s3=api.S3Upload( access_key=os.getenv("AWS_ACCESS_KEY_ID"), secret=os.getenv("AWS_SECRET_ACCESS_KEY"), session_token=os.getenv("AWS_SESSION_TOKEN"), region=os.getenv("AWS_REGION"), bucket=os.getenv("AWS_BUCKET_NAME"), ), ) ], ) egress_info = await lkapi.egress.start_room_composite_egress(req) logger.info(f"Started recording: {egress_info.egress_id}") return egress_info except Exception as e: logger.error(f"Failed to start recording of the session to be saved to S3: {e}")
t
To help you set up IAM Role-based authentication for your S3 egress in the Python code you shared, you can update the
S3Upload
section by adding the
assume_role_arn
field. This change lets LiveKit securely assume the specified IAM role for your S3 uploads. Here’s a friendly example to guide you:
Copy code
req = api.RoomCompositeEgressRequest(
    room_name=ctx.room.name,
    layout="speaker",
    preset=api.EncodingOptionsPreset.H264_720P_30,
    audio_only=False,
    file_outputs=[
        api.EncodedFileOutput(
            file_type=api.EncodedFileType.MP4,
            filepath="livekit-poc-data/recordings/recording-{room_name}-{time}.mp4",
            s3=api.S3Upload(
                access_key=os.getenv("AWS_ACCESS_KEY_ID"),  # Key with sts:AssumeRole permission
                secret=os.getenv("AWS_SECRET_ACCESS_KEY"),  # Secret for the above key
                assume_role_arn="arn:aws:iam::123456789012:role/LiveKitEgressRole",  # IAM Role ARN
                assume_role_external_id="your-external-id",  # Optional, if required by the role
                region=os.getenv("AWS_REGION"),
                bucket=os.getenv("AWS_BUCKET_NAME"),
            ),
        )
    ],
)
Just a quick note: please make sure the IAM role’s trust policy permits the credentials you provide to assume the role, and that the role has the right S3 permissions like
s3:PutObject
and
s3:PutObjectAcl
. If you have any questions or want me to walk you through any part of this, feel free to ask—I’m here to help! Sources: livekit/livekit_egress.pb.go | pkg/config/base.go