Epistemologist
Epistemologist

Reputation: 1091

Is it Possible to Use AWS Amplify Without Using Amazon Cognito?

I have android and iOS apps. I need to allow them to download and upload assets on S3, and sometimes want to send data to mobile without having to use Amazon Cognito as it costs lot of money to have. I have secret and access keys, and I want mobile users to use these keys instead of having to use Amazon Cognito.

So is it possible to use AWS Amplify without Amazon Cognito ?

Upvotes: 8

Views: 3501

Answers (2)

bdesham
bdesham

Reputation: 16089

This answer only addresses iOS, but I’m guessing that you’ll be able to do something similar on Android. Just replace “protocol” with “interface” :-)

In order to use Amplify you need to give the SDK an AWSCredentialsProvider. Luckily, this is just a protocol, not a concrete class, and it’s straightforward to implement your own:

// MyCredentialsProvider.swift

import AWSCore
import Foundation

class MyCredentialsProvider: NSObject, AWSCredentialsProvider {
    func credentials() -> AWSTask<AWSCredentials> {
        let credentials = AWSCredentials(accessKey: "AAAAAAAAAAAAAAAAAAA",
                                         secretKey: "zzzzzzzzzzzzzzzzzzz",
                                         sessionKey: nil,
                                         expiration: nil)
        return AWSTask(result: credentials)
    }

    func invalidateCachedTemporaryCredentials() {
         // I'm not entirely sure what this method is supposed to do, but it
         // seems to be okay to leave it as a no-op.
    }
}

You can use your class like this:

let provider: AWSCredentialsProvider = MyCredentialsProvider()
let serviceConfig = AWSServiceConfiguration(region: .USWest2,
                                            credentialsProvider: provider)
AWSServiceManager.default().defaultServiceConfiguration = serviceConfig

// ...actually use AWS Amplify...

Of course, you would probably want to make your credentials provider hook into your own authentication system somehow, but this at least gives you an idea of how to pass your own access key and secret key to the SDK.

Upvotes: 3

live-love
live-love

Reputation: 52484

Yes, it's possible. You don't need user authentication to use AWS Amplify.

Upvotes: -1

Related Questions