0

In order to set up a system on AWS where one can create and use user accounts from an iOS app, I recently followed this tutorial. It uses AWSMobileClient, AWSAuthCore and AWSAuthUI.

I got up something working where I can create accounts and log in and out.

Now I would like to make use of DynamoDB to allow the user to store something. For that, I have tried to integrate DynamoDB code that I have working in another app. But obviously the two apps environment are not quite the same, so it does not work as I would like it to.

Here is the code for the DynamoDB data that I want to handle:

import Foundation
import AWSDynamoDB

@objcMembers
class DynamoDBData: AWSDynamoDBObjectModel, AWSDynamoDBModeling {

    var _message,_timeStamp,_user: String?

    class func dynamoDBTableName() -> String {
        return "DynamoDBData"
    }

    class func hashKeyAttribute() -> String {
        return "_timeStamp"
    }

    class func rangeKeyAttribute() -> String {
        return "_user"
    }

    override class func jsonKeyPathsByPropertyKey() -> [AnyHashable: Any] {
        return [
            "_message" : "message",
            "_timeStamp" : "timeStamp",
            "_user" : "user"
        ]
    }
}

And here is the code for where I try to save something to the DB and get a crash:

@objc func handleTap() {
    print(#function)
    let dynamoDbObjectMapper = AWSDynamoDBObjectMapper.default() // Here the app is crashing.

    // Create data object using the data model:
    let dataBlock = DynamoDBData()
    dataBlock?._message = "message-TEST"
    dataBlock?._timeStamp = "timeStamp-TEST"
    dataBlock?._user = "user-TEST"

    // Save the new item:
    dynamoDbObjectMapper.save(dataBlock!, completionHandler: {
        (error: Error?) -> Void in

        if let error = error {
            print("Amazon DynamoDB Save Error: \(error)")
            return
        }
        print("An item was saved.")
    })
}

Finally, this is the message I get when the app is crashing:

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.'

Some guidance (even partial) on how to move forward from here would be very helpful.

1 Answer 1

1

Check that your awsconfiguration.json has the following entry:

    "DynamoDBObjectMapper": {
        "Default": {
            "Region": "AWS_REGION_NAME"
        }
    }

setting your own AWS_REGION_NAME (e.g., us-east-1).

Sign up to request clarification or add additional context in comments.

3 Comments

That seems like an excellent suggestion because it no longer crashes. But I still get an error: Amazon DynamoDB Save Error: Error Domain=com.amazonaws.AWSServiceErrorDomain Code=6 "(null)" UserInfo={__type=com.amazon.coral.service#AccessDeniedException, Message=User: arn:aws:sts::....:assumed-role/aws-amp-cog-dyn-.....-authRole/CognitoIdentityCredentials is not authorized to perform: dynamodb:UpdateItem on resource: arn:aws:dynamodb:ap-northeast-1:.....:table/DynamoDBData}
A logged in user "assumes" the "authRole" named above. Looks like this role doesn't have the right access for DynamoDB. Log into the AWS console and navigate to IAM, Roles. The auth role should be listed (as well as an unauthRole for non-logged in users). See if attaching the AmazonDynamoDBFullAccess policy to the auth role resolves the issue. (Giving full access should only be done for troubleshooting). Here's how to add a more fine grained policy: docs.aws.amazon.com/cognito/latest/developerguide/… . If access issues persist you may want to create a new question.
Indeed I have again followed your indications and made some progress. But it still does not completely work. I created a new question here: stackoverflow.com/questions/56140756/…. In the meanwhile I accept you answer because this an the comment you added obviously allowed me to make a few steps forward.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.