Skip to content

CreateParticipantToken

Source: src/AWS/IVSRealtime/CreateParticipantToken.ts

Mint a participant token that an end user presents to join the bound stage — the effectful call made from a deployed Lambda or Task. The capabilities field grants PUBLISH and/or SUBSCRIBE to the token holder; attributes attaches profile data (display name, avatar, …) that is visible to other participants. The returned token is sensitive and surfaces as a Redacted value.

Provide the CreateParticipantTokenHttp implementation layer on the Function effect, bind the stage in the init phase, then call the returned client at runtime. The binding grants ivs:CreateParticipantToken on the stage and injects its ARN automatically.

// init
const stage = yield* IVSRealtime.Stage("VideoRoom");
const createParticipantToken = yield* IVSRealtime.CreateParticipantToken(stage);
return {
fetch: Effect.gen(function* () {
// runtime
const { participantToken } = yield* createParticipantToken({
userId: "user-123",
capabilities: ["PUBLISH", "SUBSCRIBE"],
duration: "30 minutes",
attributes: { displayName: "Sam" },
});
return HttpServerResponse.json({
token:
participantToken?.token !== undefined
? Redacted.value(participantToken.token)
: undefined,
participantId: participantToken?.participantId,
});
}),
};
// on the Function effect:
// .pipe(Effect.provide(IVSRealtime.CreateParticipantTokenHttp))