Sample code for 30+ languages & platforms
Zig

SQS List Queues

See more Amazon SQS Examples

Returns a list of your Amazon SQS queues. The maximum number of queues that can be returned is 1000. If you specify a value for the optional QueueNamePrefix query parameter, only queues with a name beginning with the specified value are returned.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

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

    const rest = try chilkat.Rest.init();
    defer rest.deinit();

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

    // Provide AWS credentials for the REST call.
    const auth_aws = try chilkat.AuthAws.init();
    defer auth_aws.deinit();
    auth_aws.setAccessKey("AWS_ACCESS_KEY");
    auth_aws.setSecretKey("AWS_SECRET_KEY");
    // the region should match our URL above..
    auth_aws.setRegion("us-west-2");
    auth_aws.setServiceName("sqs");

    rest.setAuthAws(auth_aws) catch {};

    rest.addQueryParam("Action", "ListQueues") catch {};
    // List only queues having a name starting with "c".
    // Comment out this line to list all queues.
    rest.addQueryParam("QueueNamePrefix", "c") catch {};

    const response_xml = rest.fullRequestNoBody(alloc, "GET", "/") catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    // A successful response will have a status code equal to 200.
    if (rest.getResponseStatusCode() != 200) {
        std.debug.print("response status code = {d}\n", .{rest.getResponseStatusCode()});
        std.debug.print("response status text = {s}\n", .{try rest.getResponseStatusText(alloc)});
        std.debug.print("response header: {s}\n", .{try rest.getResponseHeader(alloc)});
        std.debug.print("response body: {s}\n", .{response_xml});
        return;
    }

    // Examine the successful XML response.
    const xml = try chilkat.Xml.init();
    defer xml.deinit();
    xml.loadXml(response_xml) catch {};
    std.debug.print("{s}\n", .{try xml.getXml(alloc)});
    std.debug.print("----\n", .{});

    // A successful response looks like this:
    // <?xml version="1.0" encoding="utf-8" ?>
    // <ListQueuesResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/">
    //     <ListQueuesResult>
    //         <QueueUrl>https://sqs.us-west-2.amazonaws.com/123491855557/chilkatTest</QueueUrl>
    //         <QueueUrl>https://sqs.us-west-2.amazonaws.com/123496666627/chilkatses</QueueUrl>
    //     </ListQueuesResult>
    //     <ResponseMetadata>
    //         <RequestId>77bce138-fbcc-5e42-9ee3-b15c1f7178c2</RequestId>
    //     </ResponseMetadata>
    // </ListQueuesResponse>

    // Get each queue URL..
    xml.findChild2("ListQueuesResult") catch {};
    var i: i32 = 0;
    const num_queues = xml.getNumChildren();
    while (i < num_queues) {
        std.debug.print("QueueUrl: {s}\n", .{try xml.getChildContentByIndex(alloc, i)});
        i = i + 1;
    }

    xml.getRoot2();
}