createPolicy method
Creates a policy of a specified type that you can attach to a root, an organizational unit (OU), or an individual Amazon Web Services account.
For more information about policies and their use, see Managing Organizations policies.
If the request includes tags, then the requester must have the
organizations:TagResource permission.
You can only call this operation from the management account or a member account that is a delegated administrator.
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.
The maximum size of a policy document depends on the policy's type. For more information, see Maximum and minimum values in the Organizations User Guide.
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:
- SERVICE_CONTROL_POLICY
- RESOURCE_CONTROL_POLICY
- DECLARATIVE_POLICY_EC2
- BACKUP_POLICY
- TAG_POLICY
- CHATBOT_POLICY
- AISERVICES_OPT_OUT_POLICY
- SECURITYHUB_POLICY
- UPGRADE_ROLLOUT_POLICY
- INSPECTOR_POLICY
- BEDROCK_POLICY
- S3_POLICY
- NETWORK_SECURITY_DIRECTOR_POLICY
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
Organizations resources in the Organizations User Guide.
Implementation
Future<CreatePolicyResponse> createPolicy({
required String content,
required String description,
required String name,
required PolicyType type,
List<Tag>? tags,
}) async {
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.value,
if (tags != null) 'Tags': tags,
},
);
return CreatePolicyResponse.fromJson(jsonResponse.body);
}