TLDR: How to use Amazon services with a guest/unauthenticated user ?
I have been trying to implement Amazon Kinesis video stream with a guest user to no avail. Here is what I have done or got so far.
- Followed this link and have a project ready to use with both user pool and identity pool setup.
- Have enabled unauthenticated access in my identity pool as stated in this link.
- I have gone over Getting Credentials doc but I don't think I fully understood what I needed to do. I have tried it as I understood it but did not succeed (Posting the code below).
- Have verified using the policy simulator that the roles (both Auth And UnAuth) created & associated with the identity pool have the permissions for the job (Both roles have same permissions).
Now, the thing is that it works perfectly with an amazon cognito authenticated user, but not for a guest user. The code base I have is of the sample project provided by Amazon in the first link above. To try the guest user, I just skip the login page and land directly on the channels page in the sample app. There I just invoke createSignalingChannel or describeSignalingChannel on AWSKinesisVideo and get the following error in XCode:
Error Domain=com.amazonaws.AWSKinesisVideoErrorDomain Code=1 "null" UserInfo={NSLocalizedDescription=null, NSLocalizedFailureReason=AccessDeniedException:http://internal.amazon.com/coral/com.amazon.coral.service/}
I have been looking for a way to do this for a couple of days now and the only information I have found in the documentations etc is that it is possible but have not how to do it. I think the only step that is missing is connecting the app or accessing the services as a guest user or . Console etc configuration are all set.
Code for creating channel for Kinesis video Stream sharing:
let credentialsProvider = AWSCognitoCredentialsProvider(regionType: .USEast2, identityPoolId: cognitoIdentityPoolId)
let configuration = AWSServiceConfiguration(region: .USEast2, credentialsProvider: credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
credentialsProvider.getIdentityId().continueWith(block: { (task) -> AnyObject? in
if (task.error != nil) {
print("Error: " + task.error!.localizedDescription)
}
else {
// the task result will contain the identity id
// let cognitoId = task.result!
// I don't know what to do here or what to do with this Id, this code block is here
// because it was part of getting credentials link. I have tried without it as well
}
return task;
})
// let configuration = AWSServiceConfiguration(region: self.awsRegionType, credentialsProvider: AWSMobileClient.default())
AWSKinesisVideo.register(with: configuration!, forKey: awsKinesisVideoKey) // "kinesisvideo"
self.retrieveChannelARN(channelName: channelNameValue)
if self.channelARN == nil {
self.createChannel(channelName: channelNameValue)
}
retrieveChannelARN and createChannel methods are unchanged, they are part of the sample code, as follows:
func createChannel(channelName: String) {
let kvsClient = AWSKinesisVideo(forKey: awsKinesisVideoKey)
let createSigalingChannelInput = AWSKinesisVideoCreateSignalingChannelInput.init()
createSigalingChannelInput?.channelName = channelName
kvsClient.createSignalingChannel(createSigalingChannelInput!).continueWith(block: { (task) -> Void in
if let error = task.error {
print("Error creating channel \(error)")
return
} else {
self.channelARN = task.result?.channelARN
print("Channel ARN : ", task.result?.channelARN)
}
}).waitUntilFinished()
if (self.channelARN == nil) {
let alertController = UIAlertController(title: "Unable to create channel",
message: "Please validate all the input fields",
preferredStyle: .alert)
let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil)
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)
return
}
}
func retrieveChannelARN(channelName: String) {
if !channelName.isEmpty {
let describeInput = AWSKinesisVideoDescribeSignalingChannelInput()
describeInput?.channelName = channelName
let kvsClient = AWSKinesisVideo(forKey: awsKinesisVideoKey)
kvsClient.describeSignalingChannel(describeInput!).continueWith(block: { (task) -> Void in
if let error = task.error {
print("Error describing channel: \(error)")
} else {
self.channelARN = task.result?.channelInfo?.channelARN
print("Channel ARN : ", task.result!.channelInfo!.channelARN ?? "Channel ARN empty.")
}
}).waitUntilFinished()
} else {
let alertController = UIAlertController(title: "Channel Name is Empty",
message: "Valid Channel Name is required.",
preferredStyle: .alert)
let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
return
}
}
Also I have noticed that internalCredentials property of credentialsProvider are present in authenticated user but not for the guest user, I just don't know how to remedy that. Any help with this would be appreciated. Thank you!