I am trying to integrate both S3 and Mobile Analytics, using AWS iOS SDK v2, in my Swift project. The issue is that I am trying to use two different regions (I am working with my main region, eu-west-1 in Ireland, but Mobile Analytics is only available from us-east-1 in Virginia).
I have the following in my AppDelegate to initialize Mobile Analytics:
let credentialsProviderForMobileAnalytics = AWSCognitoCredentialsProvider.credentialsWithRegionType(
AWSRegionType.USEast1,
accountId: "my_account_id",
identityPoolId: "pool_id",
unauthRoleArn: "XXX",
authRoleArn: "XXX"
)
let awsConfigurationForMobileAnalytics = AWSServiceConfiguration(
region: AWSRegionType.USEast1,
credentialsProvider: credentialsProviderForMobileAnalytics
)
AWSServiceManager.defaultServiceManager().setDefaultServiceConfiguration(awsConfigurationForMobileAnalytics)
var mobileAnalytics = AWSMobileAnalytics(forAppId: "MyAwsAppId")
Then, in a function called from a ViewController, where I want to upload an image to S3, I have:
let credentialsProviderForS3 = AWSCognitoCredentialsProvider.credentialsWithRegionType(
AWSRegionType.EUWest1,
accountId: "my_account_id",
identityPoolId: "pool_id",
unauthRoleArn: "XXX",
authRoleArn: "XXX"
)
let awsConfigurationForS3 = AWSServiceConfiguration(
region: AWSRegionType.EUWest1,
credentialsProvider: credentialsProviderForS3
)
AWSServiceManager.defaultServiceManager().setDefaultServiceConfiguration(awsConfigurationForS3)
var transferManager = AWSS3TransferManager.defaultS3TransferManager()
var fileURL = NSURL(fileURLWithPath: NSTemporaryDirectory().stringByAppendingPathComponent("temp"))
var uploadRequest1 : AWSS3TransferManagerUploadRequest = AWSS3TransferManagerUploadRequest()
uploadRequest1.bucket = "mybucket"
uploadRequest1.key = "my-image.jpeg"
uploadRequest1.body = fileURL
var task = transferManager.upload(uploadRequest1)
If I comment one of the above two sections, the corresponding task gets completed perfectly (when the code for analytics is commented, s3 works and vice versa), but it won't work together - I suspect this is because I am setting the default service configuration using AWSServiceManager.defaultServiceManager().setDefaultServiceConfiguration()
and the fact that I use two different regions somehow messes up everything. Either it refuses to log the events to Mobile Analytics, or it will interrupt the upload with the error message
NSUnderlyingError=0x17424ee20 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1001.)", NSErrorFailingURLKey=https://s3.amazonaws.com/mybucket/my-image.jpeg})
I tried setting the transfer manager for S3 like this (and commenting the setDefaultServiceConfiguration
above):
var transferManager = AWSS3TransferManager(configuration: awsConfigurationForS3, identifier: "S3")
which results in the following error during uploading:
"Error Domain=com.amazonaws.AWSS3ErrorDomain Code=0 \"The operation couldn\U2019t be completed. (com.amazonaws.AWSS3ErrorDomain error 0.)\" UserInfo=0x1742e7e00 {HostId=sm4qLUbN2XfkNYefbSU4A95UXTwvNYEBz0+bALqeFzlcXJ7rOGWnr1Yg+8HoU4r2, Bucket=mybucket, Endpoint=mybucket.s3.amazonaws.com, Message=The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint., Code=PermanentRedirect, RequestId=568728899BC328B0}"
I also tried passing "mybucket.s3.amazonaws.com" as bucket name, but this resulted in an error stating the bucket was not found.
I am really not sure what to try next. Hope you guys can give me some pointers on how to separate those two integrations, and get both working simultaneously.