Xojo Plugin AWS IAM: Create Access Key

Back to Index

Creates a new AWS secret access key and corresponding AWS access key ID for the specified user. The default status for new keys is Active.

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

CURL Command

curl -X GET https://iam.amazonaws.com/ \
  -d "Action=CreateAccessKey" \
  -d "UserName=Alice" \
  -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","CreateAccessKey")
rest.AddQueryParam("UserName","Alice")
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 CreateAccessKeyResponse_xmlns As String
Dim tagPath As String
Dim UserName As String
Dim AccessKeyId As String
Dim Status As String
Dim SecretAccessKey As String
Dim RequestId As String

CreateAccessKeyResponse_xmlns = xmlResponse.GetAttrValue("xmlns")
UserName = xmlResponse.GetChildContent("CreateAccessKeyResult|AccessKey|UserName")
AccessKeyId = xmlResponse.GetChildContent("CreateAccessKeyResult|AccessKey|AccessKeyId")
Status = xmlResponse.GetChildContent("CreateAccessKeyResult|AccessKey|Status")
SecretAccessKey = xmlResponse.GetChildContent("CreateAccessKeyResult|AccessKey|SecretAccessKey")
RequestId = xmlResponse.GetChildContent("ResponseMetadata|RequestId")

Sample XML Response Body

<?xml version="1.0" encoding="utf-8" ?>
<CreateAccessKeyResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/">
    <CreateAccessKeyResult>
        <AccessKey>
            <UserName>Alice</UserName>
            <AccessKeyId>AKIAIOSFODNN7EXAMPLE</AccessKeyId>
            <Status>Active</Status>
            <SecretAccessKey>wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY</SecretAccessKey>
        </AccessKey>
    </CreateAccessKeyResult>
    <ResponseMetadata>
        <RequestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestId>
    </ResponseMetadata>
</CreateAccessKeyResponse>