createPolicy method

Future<CreatePolicyResponse> createPolicy({
  1. required String policyDocument,
  2. required String policyName,
  3. List<Tag>? tags,
})

Creates an AWS IoT policy.

The created policy is the default version for the policy. This operation creates a policy version with a version identifier of 1 and sets 1 as the policy's default version.

May throw ResourceAlreadyExistsException. May throw MalformedPolicyException. May throw InvalidRequestException. May throw ThrottlingException. May throw UnauthorizedException. May throw ServiceUnavailableException. May throw InternalFailureException.

Parameter policyDocument : The JSON document that describes the policy. policyDocument must have a minimum length of 1, with a maximum length of 2048, excluding whitespace.

Parameter policyName : The policy name.

Parameter tags : Metadata which can be used to manage the policy.

For the CLI command-line parameter use format: &&tags "key1=value1&key2=value2..."

For the cli-input-json file use format: "tags": "key1=value1&key2=value2..."

Implementation

Future<CreatePolicyResponse> createPolicy({
  required String policyDocument,
  required String policyName,
  List<Tag>? tags,
}) async {
  ArgumentError.checkNotNull(policyDocument, 'policyDocument');
  ArgumentError.checkNotNull(policyName, 'policyName');
  _s.validateStringLength(
    'policyName',
    policyName,
    1,
    128,
    isRequired: true,
  );
  final $payload = <String, dynamic>{
    'policyDocument': policyDocument,
    if (tags != null) 'tags': tags,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/policies/${Uri.encodeComponent(policyName)}',
    exceptionFnMap: _exceptionFns,
  );
  return CreatePolicyResponse.fromJson(response);
}