createPolicy method
Creates a policy of a specified type that you can attach to a root, an organizational unit (OU), or an individual AWS account.
For more information about policies and their use, see Managing Organization Policies.
If the request includes tags, then the requester must have the
organizations:TagResource
permission.
This operation can be called only from the organization's management account.
May throw AccessDeniedException. May throw AWSOrganizationsNotInUseException. May throw ConcurrentModificationException. May throw ConstraintViolationException. May throw DuplicatePolicyException. May throw InvalidInputException. May throw MalformedPolicyDocumentException. May throw PolicyTypeNotAvailableForOrganizationException. May throw ServiceException. May throw TooManyRequestsException. May throw UnsupportedAPIEndpointException.
Parameter content
:
The policy text content to add to the new policy. The text that you supply
must adhere to the rules of the policy type you specify in the
Type
parameter.
Parameter description
:
An optional description to assign to the policy.
Parameter name
:
The friendly name to assign to the policy.
The regex pattern that is used to validate this parameter is a string of any of the characters in the ASCII character range.
Parameter type
:
The type of policy to create. You can specify one of the following values:
Parameter tags
:
A list of tags that you want to attach to the newly created policy. For
each tag in the list, you must specify both a tag key and a value. You can
set the value to an empty string, but you can't set it to
null
. For more information about tagging, see Tagging
AWS Organizations resources in the AWS Organizations User Guide.
Implementation
Future<CreatePolicyResponse> createPolicy({
required String content,
required String description,
required String name,
required PolicyType type,
List<Tag>? tags,
}) async {
ArgumentError.checkNotNull(content, 'content');
_s.validateStringLength(
'content',
content,
1,
1000000,
isRequired: true,
);
ArgumentError.checkNotNull(description, 'description');
_s.validateStringLength(
'description',
description,
0,
512,
isRequired: true,
);
ArgumentError.checkNotNull(name, 'name');
_s.validateStringLength(
'name',
name,
1,
128,
isRequired: true,
);
ArgumentError.checkNotNull(type, 'type');
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'AWSOrganizationsV20161128.CreatePolicy'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'Content': content,
'Description': description,
'Name': name,
'Type': type.toValue(),
if (tags != null) 'Tags': tags,
},
);
return CreatePolicyResponse.fromJson(jsonResponse.body);
}