-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathentry.swift
More file actions
75 lines (66 loc) · 2.28 KB
/
entry.swift
File metadata and controls
75 lines (66 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//
// An example demonstrating how to set up and use an Amazon Simple Queue
// Service client to get the attributes of an available Amazon SQS queue.
import ArgumentParser
import AWSClientRuntime
import AWSSQS
import Foundation
struct ExampleCommand: ParsableCommand {
@Argument(help: "The URL of the Amazon SQS queue to get the attributes of")
var url: String
@Option(help: "Name of the Amazon Region to use (default: us-east-1)")
var region = "us-east-1"
static var configuration = CommandConfiguration(
commandName: "getqueueattributes",
abstract: """
This example shows how to get an Amazon SQS queue's attributes.
""",
discussion: """
"""
)
/// Called by ``main()`` to run the bulk of the example.
func runAsync() async throws {
// snippet-start:[swift.sqs.GetQueueAttributes]
let config = try await SQSClient.SQSClientConfiguration(region: region)
let sqsClient = SQSClient(config: config)
let output = try await sqsClient.getQueueAttributes(
input: GetQueueAttributesInput(
attributeNames: [
.approximatenumberofmessages,
.maximummessagesize
],
queueUrl: url
)
)
guard let attributes = output.attributes else {
print("No queue attributes returned.")
return
}
for (attr, value) in attributes {
switch(attr) {
case "ApproximateNumberOfMessages":
print("Approximate message count: \(value)")
case "MaximumMessageSize":
print("Maximum message size: \(value)kB")
default:
continue
}
}
// snippet-end:[swift.sqs.GetQueueAttributes]
}
}
/// The program's asynchronous entry point.
@main
struct Main {
static func main() async {
let args = Array(CommandLine.arguments.dropFirst())
do {
let command = try ExampleCommand.parse(args)
try await command.runAsync()
} catch {
ExampleCommand.exit(withError: error)
}
}
}