Sample code for 30+ languages & platforms
Swift

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

Swift

func chilkatTest() {
    var success: Bool = false

    let rest = CkoRest()!
    var bTls: Bool = true
    var bAutoReconnect: Bool = true
    success = rest.connect(hostname: "example.com", port: 443, tls: bTls, autoReconnect: bAutoReconnect)
    if success == false {
        print("\(rest.lastErrorText!)")
        return
    }

    //  Configure AWS Signature Version 4 request signing.  Provide the access key, secret key, region,
    //  and service name.
    let authAws = CkoAuthAws()!
    //  Normally you would not hard-code secrets in source.  You should instead obtain them from an
    //  interactive prompt, environment variable, or a secrets vault.
    authAws.accessKey = "AWS_ACCESS_KEY"
    authAws.secretKey = "AWS_SECRET_KEY"
    authAws.region = "us-east-1"
    authAws.serviceName = "s3"

    //  Associate the provider so Chilkat signs each request according to AWS requirements.
    success = rest.setAuthAws(authProvider: authAws)
    if success == false {
        print("\(rest.lastErrorText!)")
        return
    }

    var responseText: String? = rest.fullRequestNoBody(httpVerb: "GET", uriPath: "/")
    if rest.lastMethodSuccess == false {
        print("\(rest.lastErrorText!)")
        return
    }

    print("\(responseText!)")

}