Sample code for 30+ languages & platforms
Xbase++

EC2 Reboot Instances

See more Amazon EC2 Examples

Demonstrates how to send a request to reboot Amazon EC2 instances.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nPort
LOCAL nBAutoReconnect
LOCAL oAuthAws
LOCAL cResponseXml
LOCAL oXml

nSuccess := 0

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

oRest := CreateObject("Chilkat.Rest")

//  Connect to the Amazon AWS server.
//  such as https://ec2.amazonaws.com/
nBTls := 1
nPort := 443
nBAutoReconnect := 1
nSuccess := oRest:Connect("ec2.us-west-2.amazonaws.com", nPort, nBTls, nBAutoReconnect)

//  Provide AWS credentials for the REST call.
oAuthAws := CreateObject("Chilkat.AuthAws")
oAuthAws:AccessKey := "AWS_ACCESS_KEY"
oAuthAws:SecretKey := "AWS_SECRET_KEY"
//  the region should match our URL above..
oAuthAws:Region := "us-west-2"
oAuthAws:ServiceName := "ec2"

oRest:SetAuthAws(oAuthAws)

oRest:AddQueryParam("Action", "RebootInstances")
oRest:AddQueryParam("Version", "2016-11-15")
oRest:AddQueryParam("DryRun", "true")
oRest:AddQueryParam("InstanceId.1", "i-999719995399c9999")

cResponseXml := oRest:FullRequestNoBody("GET", "/")
IF (oRest:LastMethodSuccess != 1)
    ? oRest:LastErrorText
    oRest:destroy()
    oAuthAws:destroy()
    RETURN
ENDIF

//  A successful response will have a status code equal to 200.
IF (oRest:ResponseStatusCode != 200)
    ? "response status code = " + Str(oRest:ResponseStatusCode)
    ? "response status text = " + oRest:ResponseStatusText
    ? "response header: " + oRest:ResponseHeader
    ? "response body: " + cResponseXml
    oRest:destroy()
    oAuthAws:destroy()
    RETURN
ENDIF

//  Examine the successful XML response.
oXml := CreateObject("Chilkat.Xml")
oXml:LoadXml(cResponseXml)
? oXml:GetXml()

oRest:destroy()
oAuthAws:destroy()
oXml:destroy()