Organizations / Client / list_policies_for_target

list_policies_for_target#

Organizations.Client.list_policies_for_target(**kwargs)#

Lists the policies that are directly attached to the specified target root, organizational unit (OU), or account. You must specify the policy type that you want included in the returned list.

Note

Always check the NextToken response parameter for a null value when calling a List* operation. These operations can occasionally return an empty set of results even when there are more results available. The NextToken response parameter value is null only when there are no more results to display.

This operation can be called only from the organization’s management account or by a member account that is a delegated administrator for an Amazon Web Services service.

See also: AWS API Documentation

Request Syntax

response = client.list_policies_for_target(
    TargetId='string',
    Filter='SERVICE_CONTROL_POLICY'|'RESOURCE_CONTROL_POLICY'|'TAG_POLICY'|'BACKUP_POLICY'|'AISERVICES_OPT_OUT_POLICY'|'CHATBOT_POLICY'|'DECLARATIVE_POLICY_EC2',
    NextToken='string',
    MaxResults=123
)
Parameters:
  • TargetId (string) –

    [REQUIRED]

    The unique identifier (ID) of the root, organizational unit, or account whose policies you want to list.

    The regex pattern for a target ID string requires one of the following:

    • Root - A string that begins with “r-” followed by from 4 to 32 lowercase letters or digits.

    • Account - A string that consists of exactly 12 digits.

    • Organizational unit (OU) - A string that begins with “ou-” followed by from 4 to 32 lowercase letters or digits (the ID of the root that the OU is in). This string is followed by a second “-” dash and from 8 to 32 additional lowercase letters or digits.

  • Filter (string) –

    [REQUIRED]

    The type of policy that you want to include in the returned list. You must specify one of the following values:

  • NextToken (string) – The parameter for receiving additional results if you receive a NextToken response in a previous request. A NextToken response indicates that more output is available. Set this parameter to the value of the previous call’s NextToken response to indicate where the output should continue from.

  • MaxResults (integer) – The total number of results that you want included on each page of the response. If you do not include this parameter, it defaults to a value that is specific to the operation. If additional items exist beyond the maximum you specify, the NextToken response element is present and has a value (is not null). Include that value as the NextToken request parameter in the next call to the operation to get the next part of the results. Note that Organizations might return fewer results than the maximum even when there are more results available. You should check NextToken after every operation to ensure that you receive all of the results.

Return type:

dict

Returns:

Response Syntax

{
    'Policies': [
        {
            'Id': 'string',
            'Arn': 'string',
            'Name': 'string',
            'Description': 'string',
            'Type': 'SERVICE_CONTROL_POLICY'|'RESOURCE_CONTROL_POLICY'|'TAG_POLICY'|'BACKUP_POLICY'|'AISERVICES_OPT_OUT_POLICY'|'CHATBOT_POLICY'|'DECLARATIVE_POLICY_EC2',
            'AwsManaged': True|False
        },
    ],
    'NextToken': 'string'
}

Response Structure

  • (dict) –

    • Policies (list) –

      The list of policies that match the criteria in the request.

      • (dict) –

        Contains information about a policy, but does not include the content. To see the content of a policy, see DescribePolicy.

        • Id (string) –

          The unique identifier (ID) of the policy.

          The regex pattern for a policy ID string requires “p-” followed by from 8 to 128 lowercase or uppercase letters, digits, or the underscore character (_).

        • Arn (string) –

          The Amazon Resource Name (ARN) of the policy.

          For more information about ARNs in Organizations, see ARN Formats Supported by Organizations in the Amazon Web Services Service Authorization Reference.

        • Name (string) –

          The friendly name of 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.

        • Description (string) –

          The description of the policy.

        • Type (string) –

          The type of policy.

        • AwsManaged (boolean) –

          A boolean value that indicates whether the specified policy is an Amazon Web Services managed policy. If true, then you can attach the policy to roots, OUs, or accounts, but you cannot edit it.

    • NextToken (string) –

      If present, indicates that more output is available than is included in the current response. Use this value in the NextToken request parameter in a subsequent call to the operation to get the next part of the output. You should repeat this until the NextToken response element comes back as null.

Exceptions

  • Organizations.Client.exceptions.AccessDeniedException

  • Organizations.Client.exceptions.AWSOrganizationsNotInUseException

  • Organizations.Client.exceptions.InvalidInputException

  • Organizations.Client.exceptions.ServiceException

  • Organizations.Client.exceptions.TargetNotFoundException

  • Organizations.Client.exceptions.TooManyRequestsException

  • Organizations.Client.exceptions.UnsupportedAPIEndpointException

Examples

The following example shows how to get a list of all service control policies (SCPs) of the type specified by the Filter parameter, that are directly attached to an account. The returned list does not include policies that apply to the account because of inheritance from its location in an OU hierarchy:/n/n

response = client.list_policies_for_target(
    Filter='SERVICE_CONTROL_POLICY',
    TargetId='444444444444',
)

print(response)

Expected Output:

{
    'Policies': [
        {
            'Arn': 'arn:aws:organizations::111111111111:policy/o-exampleorgid/service_control_policy/p-examplepolicyid222',
            'AwsManaged': False,
            'Description': 'Enables account admins to delegate permissions for any EC2 actions to users and roles in their accounts.',
            'Id': 'p-examplepolicyid222',
            'Name': 'AllowAllEC2Actions',
            'Type': 'SERVICE_CONTROL_POLICY',
        },
    ],
    'ResponseMetadata': {
        '...': '...',
    },
}