Sample code for 30+ languages & platforms
AutoIt

S3 List Buckets using an STS Session Token

See more AWS Security Token Service Examples

This is an example showing how to use an STS session token in an Amazon AWS request. This example will list S3 buckets using a previously obtained session token.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

; See Get AWS STS Session Token for sample code to get the session token XML.
$oXmlToken = ObjCreate("Chilkat.Xml")
$bSuccess = $oXmlToken.LoadXmlFile("qa_data/tokens/aws_session_token.xml")
If ($bSuccess = False) Then
    ConsoleWrite($oXmlToken.LastErrorText & @CRLF)
    Exit
EndIf

$oRest = ObjCreate("Chilkat.Rest")

; Connect to the Amazon AWS REST server.
Local $bTls = True
Local $iPort = 443
Local $bAutoReconnect = True
$bSuccess = $oRest.Connect("s3.amazonaws.com",$iPort,$bTls,$bAutoReconnect)

; Provide AWS credentials for the REST call.
$oAuthAws = ObjCreate("Chilkat.AuthAws")

; The purpose of this example is to show how to use the temporary AccessKeyId, SecretAccessKey, and SessionToken.
$oAuthAws.AccessKey = $oXmlToken.GetChildContent("GetSessionTokenResult|Credentials|AccessKeyId")
$oAuthAws.SecretKey = $oXmlToken.GetChildContent("GetSessionTokenResult|Credentials|SecretAccessKey")
$oAuthAws.ServiceName = "s3"
$bSuccess = $oRest.SetAuthAws($oAuthAws)

$oRest.AddQueryParam("X-Amz-Security-Token",$oXmlToken.GetChildContent("GetSessionTokenResult|Credentials|SessionToken"))

$oSbResponse = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oRest.FullRequestNoBodySb("GET","/",$oSbResponse)
If ($bSuccess <> True) Then
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

Local $iStatusCode = $oRest.ResponseStatusCode
ConsoleWrite("Response status code = " & $iStatusCode & @CRLF)

$oXml = ObjCreate("Chilkat.Xml")
$oXml.LoadSb($oSbResponse,True)
ConsoleWrite($oXml.GetXml() & @CRLF)

If ($iStatusCode <> 200) Then
    ConsoleWrite("Failed.  See error information in the XML." & @CRLF)
    Exit
EndIf