Rust
Rust
SNS List Topics
See more Amazon SNS Examples
List the existing SNS topics.See SNS List Topics for more information.
Chilkat Rust Downloads
// 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://sns.us-west-2.amazonaws.com/
let b_tls = true;
let port = 443;
let b_auto_reconnect = true;
let _ = rest.connect("sns.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("sns");
let _ = rest.set_auth_aws(&auth_aws);
let _ = rest.add_query_param("Action", "ListTopics");
let Ok(response_xml) = rest.full_request_no_body("GET", "/") 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 (shown below)
let xml = chilkat::Xml::new();
let _ = xml.load_xml(&response_xml);
println!("{}", xml.get_xml().unwrap_or_default());
// To iterate over the TopicArn's
let not_used = xml.chilkat_path("ListTopicsResult|Topics|$").unwrap_or_default();
let mut i = 0;
let num_topics = xml.num_children();
while i < num_topics {
let _ = xml.get_child2(i);
println!("{}", xml.get_child_content("TopicArn").unwrap_or_default());
let _ = xml.get_parent2();
i = i + 1;
}
xml.get_root2();
// A sample successful response:
// <?xml version="1.0" encoding="utf-8" ?>
// <ListTopicsResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/">
// <ListTopicsResult>
// <Topics>
// <member>
// <TopicArn>arn:aws:sns:us-west-2:957491831129:chilkat</TopicArn>
// </member>
// <member>
// <TopicArn>arn:aws:sns:us-west-2:957491831129:chilkat123</TopicArn>
// </member>
// <member>
// <TopicArn>arn:aws:sns:us-west-2:957491831129:chilkatses</TopicArn>
// </member>
// </Topics>
// </ListTopicsResult>
// <ResponseMetadata>
// <RequestId>54514f94-b07d-5f0b-9c8a-1ff85ff4ac65</RequestId>
// </ResponseMetadata>
// </ListTopicsResponse>