Xojo Plugin AWS IAM: List Groups

Back to Index

Lists the IAM groups that have the specified path prefix.

Documentation: https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListGroups.html

CURL Command

curl -X GET https://iam.amazonaws.com/ \
  -d "Action=ListGroups" \
  -d "PathPrefix=/" \
  -d "Version=2010-05-08"

Xojo Plugin Example

Dim rest As New Chilkat.Rest
Dim success As Boolean

Dim authAws As New Chilkat.AuthAws
authAws.AccessKey = "AWS_ACCESS_KEY"
authAws.SecretKey = "AWS_SECRET_KEY"
authAws.Region = "us-east-1"
authAws.ServiceName = "iam"
rest.SetAuthAws(authAws)

//  URL: https://iam.amazonaws.com/
Dim bTls As Boolean
bTls = True
Dim port As Int32
port = 443
Dim bAutoReconnect As Boolean
bAutoReconnect = True
success = rest.Connect("iam.amazonaws.com",port,bTls,bAutoReconnect)
If (success <> True) Then
    System.DebugLog("ConnectFailReason: " + Str(rest.ConnectFailReason))
    System.DebugLog(rest.LastErrorText)
    Return
End If

rest.AddQueryParam("Action","ListGroups")
rest.AddQueryParam("PathPrefix","/")
rest.AddQueryParam("Version","2010-05-08")

Dim sbResponseBody As New Chilkat.StringBuilder
success = rest.FullRequestNoBodySb("GET","/",sbResponseBody)
If (success <> True) Then
    System.DebugLog(rest.LastErrorText)
    Return
End If

Dim respStatusCode As Int32
respStatusCode = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
    System.DebugLog("Response Status Code = " + Str(respStatusCode))
    System.DebugLog("Response Header:")
    System.DebugLog(rest.ResponseHeader)
    System.DebugLog("Response Body:")
    System.DebugLog(sbResponseBody.GetAsString())
    Return
End If

Dim xmlResponse As New Chilkat.Xml
xmlResponse.LoadSb(sbResponseBody,True)

Dim i As Int32
Dim count_i As Int32
Dim tagPath As String
Dim Path As String
Dim GroupName As String
Dim GroupId As String
Dim Arn As String
Dim IsTruncated As String
Dim RequestId As String

i = 0
count_i = xmlResponse.NumChildrenHavingTag("ListGroupsResult|Groups|member")
While i < count_i
    xmlResponse.I = i
    Path = xmlResponse.GetChildContent("ListGroupsResult|Groups|member[i]|Path")
    GroupName = xmlResponse.GetChildContent("ListGroupsResult|Groups|member[i]|GroupName")
    GroupId = xmlResponse.GetChildContent("ListGroupsResult|Groups|member[i]|GroupId")
    Arn = xmlResponse.GetChildContent("ListGroupsResult|Groups|member[i]|Arn")
    i = i + 1
Wend
IsTruncated = xmlResponse.GetChildContent("ListGroupsResult|IsTruncated")
RequestId = xmlResponse.GetChildContent("ResponseMetadata|RequestId")

Sample XML Response Body

<?xml version="1.0" encoding="utf-8" ?>
<ListGroupsResponse>
    <ListGroupsResult>
        <Groups>
            <member>
                <Path>/division_abc/subdivision_xyz/</Path>
                <GroupName>Admins</GroupName>
                <GroupId>AGPACKCEVSQ6C2EXAMPLE</GroupId>
                <Arn>arn:aws:iam::123456789012:group/Admins</Arn>
            </member>
            <member>
                <Path>/division_abc/subdivision_xyz/product_1234/engineering/</Path>
                <GroupName>Test</GroupName>
                <GroupId>AGP2MAB8DPLSRHEXAMPLE</GroupId>
                <Arn>arn:aws:iam::123456789012:group
          /division_abc/subdivision_xyz/product_1234/engineering/Test</Arn>
            </member>
            <member>
                <Path>/division_abc/subdivision_xyz/product_1234/</Path>
                <GroupName>Managers</GroupName>
                <GroupId>AGPIODR4TAW7CSEXAMPLE</GroupId>
                <Arn>arn:aws:iam::123456789012
          :group/division_abc/subdivision_xyz/product_1234/Managers</Arn>
            </member>
        </Groups>
        <IsTruncated>false</IsTruncated>
    </ListGroupsResult>
    <ResponseMetadata>
        <RequestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestId>
    </ResponseMetadata>
</ListGroupsResponse>