```swift
import AWSPluginsCore

Amplify.Auth.fetchAuthSession { result in
    do {
        let session = try result.get()

        // Get user sub or identity id
        if let identityProvider = session as? AuthCognitoIdentityProvider {
            let usersub = try identityProvider.getUserSub().get()
            let identityId = try identityProvider.getIdentityId().get()
            print("User sub - \(usersub) and identity id \(identityId)")
        }

        // Get AWS credentials
        if let awsCredentialsProvider = session as? AuthAWSCredentialsProvider {
            let credentials = try awsCredentialsProvider.getAWSCredentials().get()
            // Do something with the credentials
        }

        // Get cognito user pool token
        if let cognitoTokenProvider = session as? AuthCognitoTokensProvider {
            let tokens = try cognitoTokenProvider.getCognitoTokens().get()
            // Do something with the Cognito tokens
        }

    } catch {
        print("Fetch auth session failed with error - \(error)")
    }
}
```
If you have enabled guest user in Cognito Identity Pool and no user is signed in, you will be able to access only identityId and AWS credentials. All other session details will give you an error.

```swift
import AWSPluginsCore

Amplify.Auth.fetchAuthSession { result in
    do {
        let session = try result.get()

        // Get identity id
        if let identityProvider = session as? AuthCognitoIdentityProvider {
            let identityId = try identityProvider.getIdentityId().get()
            print("Identity id \(identityId)")
        }

        // Get AWS credentials
        if let awsCredentialsProvider = session as? AuthAWSCredentialsProvider {
            let credentials = try awsCredentialsProvider.getAWSCredentials().get()
            // Do something with the credentials
        }

    } catch {
        print("Fetch auth session failed with error - \(error)")
    }
}
```
