AWS STS examples using SDK for Swift - AWS SDK for Swift

AWS STS examples using SDK for Swift

The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for Swift with AWS STS.

Actions are code excerpts that show you how to call individual service functions.

Scenarios are code examples that show you how to accomplish a specific task by calling multiple functions within the same service.

Each example includes a link to GitHub, where you can find instructions on how to set up and run the code in context.



The following code example shows how to assume a role with AWS STS.

SDK for Swift

This is prerelease documentation for an SDK in preview release. It is subject to change.


There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

public func assumeRole(role: IAMClientTypes.Role, sessionName: String) async throws -> STSClientTypes.Credentials { let input = AssumeRoleInput( roleArn: role.arn, roleSessionName: sessionName ) do { let output = try await stsClient.assumeRole(input: input) guard let credentials = output.credentials else { throw ServiceHandlerError.authError } return credentials } catch { throw error } }
  • For API details, see AssumeRole in AWS SDK for Swift API reference.