Assume Role
Obtain temporary AWS credentials for MQTT or video streaming.
userInstance — ESPRMUser from User sign in.
What This Module Does ?
assumeRole returns short-lived accessKey, secretKey, and sessionToken for RainMaker-backed services—typically MQTT for live device data or video stream for camera WebRTC (Kinesis Video Streams).
Use when your client connects directly to AWS MQTT/KVS—not for ordinary REST calls through the SDK.
Expected outcome: Credentials scoped to the requested role and optional group or node IDs.
Common Workflows
MQTT credentials
import { ESPUserRole } from "@espressif/rainmaker-base-sdk";
const credentials = await userInstance.assumeRole({
userRole: ESPUserRole.MQTT,
groupIds: ["group_id_1"],
});
Video stream credentials
const credentials = await userInstance.assumeRole({
userRole: ESPUserRole.VIDEOSTREAM,
nodeIds: ["camera_node_id"],
});
Use the response with your AWS/KVS or WebRTC client. Resolve IDs via Get Groups and Node Management.
Error Handling
try {
await userInstance.assumeRole({ userRole: ESPUserRole.VIDEOSTREAM, nodeIds: [] });
} catch (error) {
console.error("Assume role failed:", error);
}
videostream requires at least one nodeId. Do not pass both groupIds and nodeIds in one request.
Advanced Concepts
Roles
| Role | Value | Purpose |
|---|---|---|
| MQTT | mqtt | Default; MQTT for groups or nodes |
| Video stream | videostream | Camera streaming; requires nodeIds |
Omit userRole to default to mqtt.
Validation
- Max 5
groupIdsand 5nodeIds - Not both
groupIdsandnodeIdsin the same call videostreammust include at least onenodeId- For
mqttwith empty IDs, credentials may cover all groups the user can access
Treat credentials as secrets. Do not log them. Refresh before expiry per your AWS client.
Best Practices
- Request minimal scope—pass specific
groupIdsornodeIdswhen possible - Do not persist credentials longer than the session needs
- Use Sessions for user auth tokens;
assumeRoleis separate from login
Related Resource
- Session Management
- API Reference: