Sample code for 30+ languages & platforms
Tcl

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 Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

set rest [new_CkRest]

set bTls 1
set bAutoReconnect 1
set success [CkRest_Connect $rest "example.com" 443 $bTls $bAutoReconnect]
if {$success == 0} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    exit
}

#  Configure AWS Signature Version 4 request signing.  Provide the access key, secret key, region,
#  and service name.
set authAws [new_CkAuthAws]

#  Normally you would not hard-code secrets in source.  You should instead obtain them from an
#  interactive prompt, environment variable, or a secrets vault.
CkAuthAws_put_AccessKey $authAws "AWS_ACCESS_KEY"
CkAuthAws_put_SecretKey $authAws "AWS_SECRET_KEY"
CkAuthAws_put_Region $authAws "us-east-1"
CkAuthAws_put_ServiceName $authAws "s3"

#  Associate the provider so Chilkat signs each request according to AWS requirements.
set success [CkRest_SetAuthAws $rest $authAws]
if {$success == 0} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    exit
}

set responseText [CkRest_fullRequestNoBody $rest "GET" "/"]
if {[CkRest_get_LastMethodSuccess $rest] == 0} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    exit
}

puts "$responseText"

delete_CkRest $rest
delete_CkAuthAws $authAws