Sample code for 30+ languages & platforms
Rust

SQS Purge Queue

See more Amazon SQS Examples

Deletes all the messages in an SQS queue.

See SQS PurgeQueue or detailed information.

Chilkat Rust Downloads

Rust

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

let rest = chilkat::Rest::new();

// Connect to the Amazon AWS REST server.
// such as https://sqs.us-west-2.amazonaws.com/
let b_tls = true;
let port = 443;
let b_auto_reconnect = true;
let _ = rest.connect("sqs.us-west-2.amazonaws.com", port, b_tls, b_auto_reconnect).is_ok();

// Provide AWS credentials for the REST call.
let auth_aws = chilkat::AuthAws::new();
auth_aws.set_access_key("AWS_ACCESS_KEY");
auth_aws.set_secret_key("AWS_SECRET_KEY");
// the region should match our URL above..
auth_aws.set_region("us-west-2");
auth_aws.set_service_name("sqs");

let _ = rest.set_auth_aws(&auth_aws);

let _ = rest.add_query_param("Action", "PurgeQueue");

// Use the actual path part of your SQS queue URL here:
let Ok(response_xml) = rest.full_request_no_body("GET", "/123456789123/chilkatTest") else {
    println!("{}", rest.last_error_text());
    return;
};

// A successful response will have a status code equal to 200.
if rest.response_status_code() != 200 {
    println!("response status code = {}", rest.response_status_code());
    println!("response status text = {}", rest.response_status_text());
    println!("response header: {}", rest.response_header());
    println!("response body: {}", response_xml);
    return;
}

// Examine the successful XML response.
let xml = chilkat::Xml::new();
let _ = xml.load_xml(&response_xml);
println!("{}", xml.get_xml().unwrap_or_default());

// A sample PurgeQueue response:
// <PurgeQueueResponse>
//     <ResponseMetadata>
//         <RequestId>
//             6fde8d1e-52cd-4581-8cd9-c512f4c64223
//         </RequestId>
//     </ResponseMetadata>
// </PurgeQueueResponse>