Skip to content

Commit 614be06

Browse files
authored
Swift: Add scenario example for SNS and SQS (#7359)
1 parent 5cf014d commit 614be06

File tree

6 files changed

+800
-4
lines changed

6 files changed

+800
-4
lines changed

.doc_gen/metadata/sqs_metadata.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,15 @@ sqs_Scenario_TopicsAndQueues:
11171117
excerpts:
11181118
- snippet_tags:
11191119
- sns.kotlin.workflow.main
1120+
Swift:
1121+
versions:
1122+
- sdk_version: 1
1123+
github: swift/example_code/sqs/scenario
1124+
sdkguide:
1125+
excerpts:
1126+
- description:
1127+
snippet_tags:
1128+
- swift.sqs.scenario.main
11201129
services:
11211130
sns: {CreateTopic, Subscribe, Publish, Unsubscribe, DeleteTopic}
11221131
sqs: {CreateQueue, GetQueueAttributes, SetQueueAttributes, ReceiveMessage, DeleteMessageBatch, DeleteQueue}

swift/example_code/s3/ListBuckets-Simple/Sources/entry.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import AWSClientRuntime
1111
import AWSS3
1212
import Foundation
13-
1413
// snippet-end:[s3.swift.intro.imports]
1514

1615
// snippet-start:[s3.swift.intro.getbucketnames]
@@ -56,11 +55,10 @@ func getBucketNames() async throws -> [String] {
5655
}
5756
}
5857
}
59-
6058
// snippet-end:[s3.swift.intro.getbucketnames]
6159

62-
// snippet-start:[s3.swift.intro.main]
6360
/// The program's asynchronous entry point.
61+
// snippet-start:[s3.swift.intro.main]
6462
@main
6563
struct Main {
6664
static func main() async {
@@ -78,5 +76,4 @@ struct Main {
7876
}
7977
}
8078
}
81-
8279
// snippet-end:[s3.swift.intro.main]

swift/example_code/sns/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ Code excerpts that show you how to call individual service functions.
4545
- [Subscribe](SubscribeEmail/Sources/entry.swift#L31)
4646
- [Unsubscribe](Unsubscribe/Sources/entry.swift#L29)
4747

48+
### Scenarios
49+
50+
Code examples that show you how to accomplish a specific task by calling multiple
51+
functions within the same service.
52+
53+
- [Publish messages to queues](../sqs/scenario/Sources/entry.swift)
54+
4855

4956
<!--custom.examples.start-->
5057
<!--custom.examples.end-->
@@ -74,6 +81,22 @@ This example shows you how to get started using Amazon SNS.
7481

7582

7683

84+
#### Publish messages to queues
85+
86+
This example shows you how to do the following:
87+
88+
- Create topic (FIFO or non-FIFO).
89+
- Subscribe several queues to the topic with an option to apply a filter.
90+
- Publish messages to the topic.
91+
- Poll the queues for messages received.
92+
93+
<!--custom.scenario_prereqs.sqs_Scenario_TopicsAndQueues.start-->
94+
<!--custom.scenario_prereqs.sqs_Scenario_TopicsAndQueues.end-->
95+
96+
97+
<!--custom.scenarios.sqs_Scenario_TopicsAndQueues.start-->
98+
<!--custom.scenarios.sqs_Scenario_TopicsAndQueues.end-->
99+
77100
### Tests
78101

79102
⚠ Running tests might result in charges to your AWS account.

swift/example_code/sqs/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ Code excerpts that show you how to call individual service functions.
4646
- [ReceiveMessage](ReceiveMessage/Sources/entry.swift#L31)
4747
- [SetQueueAttributes](SetQueueAttributes/Sources/entry.swift#L32)
4848

49+
### Scenarios
50+
51+
Code examples that show you how to accomplish a specific task by calling multiple
52+
functions within the same service.
53+
54+
- [Publish messages to queues](scenario/Sources/entry.swift)
55+
4956

5057
<!--custom.examples.start-->
5158
<!--custom.examples.end-->
@@ -75,6 +82,22 @@ This example shows you how to get started using Amazon SQS.
7582

7683

7784

85+
#### Publish messages to queues
86+
87+
This example shows you how to do the following:
88+
89+
- Create topic (FIFO or non-FIFO).
90+
- Subscribe several queues to the topic with an option to apply a filter.
91+
- Publish messages to the topic.
92+
- Poll the queues for messages received.
93+
94+
<!--custom.scenario_prereqs.sqs_Scenario_TopicsAndQueues.start-->
95+
<!--custom.scenario_prereqs.sqs_Scenario_TopicsAndQueues.end-->
96+
97+
98+
<!--custom.scenarios.sqs_Scenario_TopicsAndQueues.start-->
99+
<!--custom.scenarios.sqs_Scenario_TopicsAndQueues.end-->
100+
78101
### Tests
79102

80103
⚠ Running tests might result in charges to your AWS account.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// swift-tools-version: 5.9
2+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// The swift-tools-version declares the minimum version of Swift required to
6+
// build this package.
7+
8+
import PackageDescription
9+
10+
let package = Package(
11+
name: "queue-scenario",
12+
// Let Xcode know the minimum Apple platforms supported.
13+
platforms: [
14+
.macOS(.v13),
15+
.iOS(.v15)
16+
],
17+
dependencies: [
18+
// Dependencies declare other packages that this package depends on.
19+
.package(
20+
url: "https://github.com/awslabs/aws-sdk-swift",
21+
from: "1.0.0"),
22+
.package(
23+
url: "https://github.com/apple/swift-argument-parser.git",
24+
branch: "main"
25+
)
26+
],
27+
targets: [
28+
// Targets are the basic building blocks of a package, defining a module or a test suite.
29+
// Targets can depend on other targets in this package and products
30+
// from dependencies.
31+
.executableTarget(
32+
name: "queue-scenario",
33+
dependencies: [
34+
.product(name: "AWSSNS", package: "aws-sdk-swift"),
35+
.product(name: "AWSSQS", package: "aws-sdk-swift"),
36+
.product(name: "ArgumentParser", package: "swift-argument-parser")
37+
],
38+
path: "Sources")
39+
40+
]
41+
)

0 commit comments

Comments
 (0)