Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 478
Epistemologist Avatar asked Jan 31 '19 10:01

Epistemologist


People also ask

Does amplify use Cognito?

The Amplify Framework uses Amazon Cognito as the main authentication provider.

Can I use AWS Cognito without amplify?

AWS Cognito integration with amazon-cognito-identity-js The common approach to integrate Cognito into a single-page app is to use Amplify library. However, using the entire Amplify library may be overkill if we only want to use it for implementing Cognito authentication features in our app.

Is AWS amplify easy to use?

Easy to start, easy to scale. Create full-stack apps, frontend UI and backends visually, with authentication, storage, data, and more. Connect web and mobile apps to new and existing AWS resources in a few lines of code.


1 Answers

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.

like image 68
bdesham Avatar answered Nov 12 '22 15:11

bdesham