Xojo Plugin AWS IAM: List Users

Back to Index

Lists the IAM users that have the specified path prefix. If no path prefix is specified, the operation returns all users in the AWS account. If there are none, the operation returns an empty list. .

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

CURL Command

curl -X GET https://iam.amazonaws.com/ \
  -d "Action=ListUsers" \
  -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","ListUsers")
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 ListUsersResponse_xmlns As String
Dim i As Int32
Dim count_i As Int32
Dim tagPath As String
Dim UserId As String
Dim Path As String
Dim UserName As String
Dim Arn As String
Dim CreateDate As String
Dim PasswordLastUsed As String
Dim IsTruncated As String
Dim RequestId As String

ListUsersResponse_xmlns = xmlResponse.GetAttrValue("xmlns")
i = 0
count_i = xmlResponse.NumChildrenHavingTag("ListUsersResult|Users|member")
While i < count_i
    xmlResponse.I = i
    UserId = xmlResponse.GetChildContent("ListUsersResult|Users|member[i]|UserId")
    Path = xmlResponse.GetChildContent("ListUsersResult|Users|member[i]|Path")
    UserName = xmlResponse.GetChildContent("ListUsersResult|Users|member[i]|UserName")
    Arn = xmlResponse.GetChildContent("ListUsersResult|Users|member[i]|Arn")
    CreateDate = xmlResponse.GetChildContent("ListUsersResult|Users|member[i]|CreateDate")
    PasswordLastUsed = xmlResponse.GetChildContent("ListUsersResult|Users|member[i]|PasswordLastUsed")
    i = i + 1
Wend
IsTruncated = xmlResponse.GetChildContent("ListUsersResult|IsTruncated")
RequestId = xmlResponse.GetChildContent("ResponseMetadata|RequestId")

Sample XML Response Body

<?xml version="1.0" encoding="utf-8" ?>
<ListUsersResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/">
    <ListUsersResult>
        <Users>
            <member>
                <UserId>AID2MAB8DPLSRHEXAMPLE</UserId>
                <Path>/division_abc/subdivision_xyz/engineering/</Path>
                <UserName>Andrew</UserName>
                <Arn>arn:aws:iam::123456789012:user/division_abc/subdivision_xyz/engineering/Andrew</Arn>
                <CreateDate>2012-09-05T19:38:48Z</CreateDate>
                <PasswordLastUsed>2014-09-08T21:47:36Z</PasswordLastUsed>
            </member>
            <member>
                <UserId>AIDIODR4TAW7CSEXAMPLE</UserId>
                <Path>/division_abc/subdivision_xyz/engineering/</Path>
                <UserName>Jackie</UserName>
                <Arn>arn:aws:iam::123456789012:user/division_abc/subdivision_xyz/engineering/Jackie</Arn>
                <CreateDate>2014-04-09T15:43:45Z</CreateDate>
                <PasswordLastUsed>2014-09-24T16:18:07Z</PasswordLastUsed>
            </member>
        </Users>
        <IsTruncated>false</IsTruncated>
    </ListUsersResult>
    <ResponseMetadata>
        <RequestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestId>
    </ResponseMetadata>
</ListUsersResponse>