attachThingPrincipal method

Future<void> attachThingPrincipal({
  1. required String principal,
  2. required String thingName,
  3. ThingPrincipalType? thingPrincipalType,
})

Attaches the specified principal to the specified thing. A principal can be X.509 certificates, Amazon Cognito identities or federated identities.

Requires permission to access the AttachThingPrincipal action.

May throw InternalFailureException. May throw InvalidRequestException. May throw ResourceNotFoundException. May throw ServiceUnavailableException. May throw ThrottlingException. May throw UnauthorizedException.

Parameter principal : The principal, which can be a certificate ARN (as returned from the CreateCertificate operation) or an Amazon Cognito ID.

Parameter thingName : The name of the thing.

Parameter thingPrincipalType : The type of the relation you want to specify when you attach a principal to a thing.

  • EXCLUSIVE_THING - Attaches the specified principal to the specified thing, exclusively. The thing will be the only thing that’s attached to the principal.
  • NON_EXCLUSIVE_THING - Attaches the specified principal to the specified thing. Multiple things can be attached to the principal.

Implementation

Future<void> attachThingPrincipal({
  required String principal,
  required String thingName,
  ThingPrincipalType? thingPrincipalType,
}) async {
  final headers = <String, String>{
    'x-amzn-principal': principal.toString(),
  };
  final $query = <String, List<String>>{
    if (thingPrincipalType != null)
      'thingPrincipalType': [thingPrincipalType.value],
  };
  final response = await _protocol.send(
    payload: null,
    method: 'PUT',
    requestUri: '/things/${Uri.encodeComponent(thingName)}/principals',
    queryParams: $query,
    headers: headers,
    exceptionFnMap: _exceptionFns,
  );
}