Skip to content

Migration to Amplify SDK Android

0

We have an Android application that uses AWS Mobile SDK. Our app uses cognito to authenticate and store files in S3. We got an email that AWS Mobile SDK is deprecated and no new features will be implemented, so we want to migrate into Amplify SDK. The problem is that there are not helpful migration guides/samples/examples on how to do it on our case.

We use a custom implementation of AWSAbstractCognitoDeveloperIdentityProvider that retrieves identityId and token from our backend service. This custom implementation is injected in CognitoCachingCredentialsProvider and the CognitoCachingCredentialsProvider is used to build an AmazonS3Client. Then we use this AmazonS3Client to build a TransferUtility that helps us to upload/download files.

I found examples on how to upload/download files with Amplify SDK on public buckets. I found examples on how to upload/download files with Amplify SDK on private buckets after signing in with facebook/google/apple, etc. I could not find something that helps me to authenticate our app through cognito as we do with AWS Mobile SDK

Can you help please?

asked 2 months ago88 views
1 Answer
0

To migrate from AWS Mobile SDK to Amplify SDK for Android, you'll need to adapt your custom authentication approach to work with Amplify's storage capabilities. Here's how you can approach this migration:

First, you'll need to add the necessary Amplify dependencies to your Android project. In your app's build.gradle file, you should include both the Amplify core libraries and the specific modules for authentication and storage:

dependencies {
// Amplify core
implementation 'com.amplifyframework:aws-auth-cognito:x.x.x'
implementation 'com.amplifyframework:aws-storage-s3:x.x.x'
}

The aws-auth-cognito library is specifically required to provide authentication for Amazon S3 operations.

For your custom authentication scenario where you're retrieving identity IDs and tokens from your backend service, you'll need to implement a custom authentication plugin for Amplify. This would replace your current custom implementation of AWSAbstractCognitoDeveloperIdentityProvider.

After configuring the authentication, you can initialize Amplify in your application class:

Amplify.addPlugin(new AWSCognitoAuthPlugin());
Amplify.addPlugin(new AWSS3StoragePlugin());
Amplify.configure(getApplicationContext());

Then, you can use Amplify's Storage API to upload and download files, which will replace your current usage of TransferUtility:

// Upload example
Amplify.Storage.uploadFile(
"example.txt",
new File("/path/to/file"),
result -> Log.i("MyApp", "Upload succeeded"),
error -> Log.e("MyApp", "Upload failed", error)
);

// Download example
Amplify.Storage.downloadFile(
"example.txt",
new File("/path/to/download/location"),
result -> Log.i("MyApp", "Download succeeded"),
error -> Log.e("MyApp", "Download failed", error)
);

Note that with Amplify, users must be signed in or you must configure guest access before using storage features. Since you're retrieving authentication tokens from your backend, you'll need to ensure these are properly integrated with Amplify's authentication system.

AWS Amplify is the recommended path forward for developing new cloud-connected Android apps, as the AWS Mobile SDK is no longer being updated or supported with new features.
Sources
AWS Mobile for Android and iOS - AWS Mobile Hub
Set up Storage - Android - AWS Amplify Gen 2 Documentation

answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.