0

I am using and starting to understand AWS for use in my objective-c ios app. I have migrated from parse and now am learning to use NoSQL/DynamoDB to store all my data. I have both the aws-sdk and crypto in use in AWS Lambda functions (but am open to others).

How do I create objectIds that are unique for my database objects (like parse used like 10 alphanumeric characters per each record)?

Say I have a bunch of pictures being uploaded via my app and I want a unique id for each. What's the best way to do this for DynamoDB?

I would also hope that the picture object id could also have a secondary index of the userid. Thanks.

cdub
  • 24,555
  • 57
  • 174
  • 303

2 Answers2

0

If you can't find a way using a combination of existing fields for the index create a universally unique identifier (UUID); lookup(google), creating a UUID for the language you're using. Or try to come up with something creative and potentially more useful like: image_file_name+upload_date_time_+image_owner

Stafford
  • 51
  • 3
0

You can create the unique id for your images/objects, by using something like this,

func randomStringWithLength(len: Int) -> NSString {
    let letters : NSString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    let randomString : NSMutableString = NSMutableString(capacity: len)
    for _ in 0 ..< len {
        let length = UInt32 (letters.length)
        let rand = arc4random_uniform(length)
        randomString.appendFormat("%C", letters.characterAtIndex(Int(rand)))
    }
    return randomString
}

To ensure the high uniqueness, just append the time stamp(current date and time while uploading image/objects) with the random string which is generated using above method.

Karthick Selvaraj
  • 2,387
  • 17
  • 28