createPolicy method

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

Creates an 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.

Requires permission to access the CreatePolicy action.

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

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 {
  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);
}