Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWSS3 Region / plist configuration issue 'The service configuration is `nil`

I am facing a strange issue with AWSS3.

Setup:

  • AWS Mobile HUB
  • Cognito
  • DynamoDB
  • S3

--> Cognito, Dynamo & even S3 (through cognito user data) work.

However I now tried to connect directly to AWS3 with the following code:"

let transferManager = AWSS3TransferManager.default()
                            let uploadRequest = AWSS3TransferManagerUploadRequest()
                            uploadRequest?.bucket = "XXXXXXXXXXXX"
                            uploadRequest?.key = "user-data/" + awsId! + "/primary_profile_picture.png"
                            uploadRequest?.body = imgUrl as URL

                            transferManager.upload(uploadRequest!).continueWith(executor: AWSExecutor.mainThread(), block: { (task:AWSTask<AnyObject>) -> Any? in

                                if let error = task.error as? NSError {
                                    if error.domain == AWSS3TransferManagerErrorDomain, let code = AWSS3TransferManagerErrorType(rawValue: error.code) {
                                        switch code {
                                        case .cancelled, .paused:
                                            break
                                        default:
                                            print("Error uploading: \(uploadRequest?.key) Error: \(error)")
                                        }
                                    } else {
                                        print("Error uploading: \(uploadRequest?.key) Error: \(error)")
                                    }
                                    return nil
                                }

                                let uploadOutput = task.result
                                print("Upload complete for: \(uploadRequest?.key)")
                                return nil
                            })

and am getting the error:

AWSiOSSDK v2.5.1 [Debug] AWSInfo.m line:122 | -[AWSServiceInfo initWithInfoDictionary:checkRegion:] | Couldn't read the region configuration from Info.plist for the client. Please check your `Info.plist` if you are providing the SDK configuration values through `Info.plist`.
2017-02-20 19:29:21.748997 [2210:1152801] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The service configuration is `nil`. You need to configure `Info.plist` or set `defaultServiceConfiguration` before using this method.'

I am using the downloaded plist configuration from AWS Mobiel HUB and am therfore a bit surprised that it does not work (as all other components do).

Any ideas what the issue might be? The plist actually contains the bucket ID & region.

like image 325
Sebastian Flückiger Avatar asked Feb 20 '17 18:02

Sebastian Flückiger


4 Answers

For me, I had to configure the credentials with the following code, before uploading:

let credentialsProvider = AWSCognitoCredentialsProvider(regionType:.USEast1,identityPoolId:PoolID)
let configuration = AWSServiceConfiguration(region:.USEast1, credentialsProvider:credentialsProvider)

AWSServiceManager.default().defaultServiceConfiguration = configuration

Where PoolID is my Cognito identity. I hope this helps others.

like image 176
Francois Nadeau Avatar answered Oct 25 '22 18:10

Francois Nadeau


Your info.plist needs to have S3TransferManager in it.

So, **AWS -> S3TransferManager -> Default -> Region -> ...**

You can find an example of one here

like image 41
Lisa M Shon Avatar answered Oct 25 '22 17:10

Lisa M Shon


Swift 3 - Xcode 8.3.3

For people still having this issue, I just spent 3h fighting against this annoying setup issue.

I added both these chunks in my Info.plist (replace the variables between ** ** in the second bloc) and now it's working again.

Amazon's documentation isn't updated properly I think. I hope this can save some people some time.

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>amazonaws.com</key>
            <dict>
                <key>NSThirdPartyExceptionMinimumTLSVersion</key>
                <string>TLSv1.0</string>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSIncludesSubdomains</key>
                <true/>
            </dict>
            <key>amazonaws.com.cn</key>
            <dict>
                <key>NSThirdPartyExceptionMinimumTLSVersion</key>
                <string>TLSv1.0</string>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSIncludesSubdomains</key>
                <true/>
            </dict>
        </dict>
    </dict>

and:

<key>AWS</key>
    <dict>
        <key>CredentialsProvider</key>
        <dict>
            <key>CognitoIdentity</key>
            <dict>
                <key>Default</key>
                <dict>
                    <key>PoolId</key>
                    <string>**YourCognitoIdentityPoolId**</string>
                    <key>Region</key>
                    <string>**AWSRegionUnknown**</string>
                </dict>
            </dict>
        </dict>
        <key>S3TransferManager</key>
        <dict>
            <key>Default</key>
            <dict>
                <key>Region</key>
                <string>**AWSRegionUnknown**</string>
            </dict>
        </dict>
    </dict>
like image 42
Edouard Barbier Avatar answered Oct 25 '22 18:10

Edouard Barbier


I had the same issue instead of S3TransferManager you should put DynamoDBObjectMapper

e.g..

<key>DynamoDBObjectMapper</key>
    <dict>
        <key>Default</key>
        <dict>
            <key>Region</key>
            <string>us-east-1</string>
        </dict>
    </dict>
like image 45
Gael Musi Avatar answered Oct 25 '22 18:10

Gael Musi