44/// A simple example that shows how to use the AWS SDK for Swift to
55/// authenticate using optional static credentials and an AWS IAM role ARN.
66
7- // snippet-start:[swift.AssumeRole.imports]
7+ // snippet-start:[swift.sts. AssumeRole.imports]
88import ArgumentParser
99import AWSClientRuntime
1010import AWSS3
1111import AWSSDKIdentity
1212import AWSSTS
1313import Foundation
1414import SmithyIdentity
15- // snippet-end:[swift.AssumeRole.imports]
15+ // snippet-end:[swift.sts. AssumeRole.imports]
1616
1717struct ExampleCommand : ParsableCommand {
1818 @Option ( help: " AWS access key ID " )
@@ -41,7 +41,7 @@ struct ExampleCommand: ParsableCommand {
4141
4242 /// Called by ``main()`` to do the actual running of the AWS
4343 /// example.
44- // snippet-start:[swift.AssumeRole.command.runasync]
44+ // snippet-start:[swift.sts. AssumeRole.command.runasync]
4545 func runAsync( ) async throws {
4646 // If credentials are specified, create a credential identity
4747 // resolver that uses them to authenticate. This identity will be used
@@ -64,7 +64,7 @@ struct ExampleCommand: ParsableCommand {
6464 // or using the default credentials if none were specified.
6565
6666 do {
67- // snippet-start: [swift.AssumeRole.use-role-credentials ]
67+ // snippet-start: [swift.sts.AssumeRole ]
6868 let credentials = try await assumeRole ( identityResolver: identityResolver,
6969 roleArn: roleArn)
7070 do {
@@ -78,7 +78,7 @@ struct ExampleCommand: ParsableCommand {
7878 dump ( error) )
7979 throw error
8080 }
81- // snippet-end: [swift.AssumeRole.use-role-credentials ]
81+ // snippet-end: [swift.sts.AssumeRole ]
8282 } catch {
8383 print ( " ERROR: Error assuming role in runAsync: " , dump ( error) )
8484 throw AssumeRoleExampleError . assumeRoleFailed
@@ -98,7 +98,7 @@ struct ExampleCommand: ParsableCommand {
9898 throw error
9999 }
100100 }
101- // snippet-end:[swift.AssumeRole.command.runasync]
101+ // snippet-end:[swift.sts. AssumeRole.command.runasync]
102102}
103103
104104/// An `Error` type used to return errors from the
@@ -125,7 +125,7 @@ enum AssumeRoleExampleError: Error {
125125 }
126126}
127127
128- // snippet-start:[swift.AssumeRole.assumeRole-function]
128+ // snippet-start:[swift.sts. AssumeRole.assumeRole-function]
129129/// Assume the specified role. If any kind of credential identity resolver is
130130/// specified, that identity is adopted before assuming the role.
131131///
@@ -148,7 +148,7 @@ func assumeRole(identityResolver: (any AWSCredentialIdentityResolver)?,
148148
149149 // Assume the role and return the assigned credentials.
150150
151- // snippet-start: [swift.sts.AssumeRole]
151+ // snippet-start: [swift.sts.sts. AssumeRole]
152152 let input = AssumeRoleInput (
153153 roleArn: roleArn,
154154 roleSessionName: " AssumeRole-Example "
@@ -165,7 +165,7 @@ func assumeRole(identityResolver: (any AWSCredentialIdentityResolver)?,
165165 let sessionToken = credentials. sessionToken else {
166166 throw AssumeRoleExampleError . incompleteCredentials
167167 }
168- // snippet-end: [swift.sts.AssumeRole]
168+ // snippet-end: [swift.sts.sts. AssumeRole]
169169
170170 // Return an `AWSCredentialIdentity` object with the temporary
171171 // credentials.
@@ -177,7 +177,7 @@ func assumeRole(identityResolver: (any AWSCredentialIdentityResolver)?,
177177 )
178178 return awsCredentials
179179}
180- // snippet-end:[swift.AssumeRole.assumeRole-function]
180+ // snippet-end:[swift.sts. AssumeRole.assumeRole-function]
181181
182182/// Return an array containing the names of all available buckets using
183183/// the specified credential identity resolver to authenticate.
@@ -193,7 +193,7 @@ func getBucketNames(identityResolver: (any AWSCredentialIdentityResolver)?)
193193 async throws -> [ String ] {
194194 do {
195195 // Get an S3Client with which to access Amazon S3.
196- // snippet-start:[swift.AssumeRole.use-resolver]
196+ // snippet-start:[swift.sts. AssumeRole.use-resolver]
197197 let configuration = try await S3Client . S3ClientConfiguration (
198198 awsCredentialIdentityResolver: identityResolver
199199 )
@@ -204,7 +204,7 @@ func getBucketNames(identityResolver: (any AWSCredentialIdentityResolver)?)
204204 let pages = client. listBucketsPaginated (
205205 input: ListBucketsInput ( maxBuckets: 10 )
206206 )
207- // snippet-end:[swift.AssumeRole.use-resolver]
207+ // snippet-end:[swift.sts. AssumeRole.use-resolver]
208208
209209 // Get the bucket names.
210210 var bucketNames : [ String ] = [ ]
0 commit comments