Sample code for 30+ languages & platforms
Xbase++

Configure AWS Signature Authentication for REST

See more REST Examples

Demonstrates Rest.SetAuthAws, which associates an AuthAws provider so Chilkat signs each request using AWS Signature Version 4. The provider supplies the access key, secret key, region, and service name.

Background. AWS requires each request to be signed with a signature derived from the secret key, region, service, and request contents. Configuring the provider lets Chilkat compute and attach the signature automatically.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nBAutoReconnect
LOCAL oAuthAws
LOCAL cResponseText

nSuccess := 0

oRest := CreateObject("Chilkat.Rest")
nBTls := 1
nBAutoReconnect := 1
nSuccess := oRest:Connect("example.com", 443, nBTls, nBAutoReconnect)
IF (nSuccess == 0)
    ? oRest:LastErrorText
    oRest:destroy()
    RETURN
ENDIF

//  Configure AWS Signature Version 4 request signing.  Provide the access key, secret key, region,
//  and service name.
oAuthAws := CreateObject("Chilkat.AuthAws")
//  Normally you would not hard-code secrets in source.  You should instead obtain them from an
//  interactive prompt, environment variable, or a secrets vault.
oAuthAws:AccessKey := "AWS_ACCESS_KEY"
oAuthAws:SecretKey := "AWS_SECRET_KEY"
oAuthAws:Region := "us-east-1"
oAuthAws:ServiceName := "s3"

//  Associate the provider so Chilkat signs each request according to AWS requirements.
nSuccess := oRest:SetAuthAws(oAuthAws)
IF (nSuccess == 0)
    ? oRest:LastErrorText
    oRest:destroy()
    oAuthAws:destroy()
    RETURN
ENDIF

cResponseText := oRest:FullRequestNoBody("GET", "/")
IF (oRest:LastMethodSuccess == 0)
    ? oRest:LastErrorText
    oRest:destroy()
    oAuthAws:destroy()
    RETURN
ENDIF

? cResponseText

oRest:destroy()
oAuthAws:destroy()