Aws-sdk-android: AmazonS3Client(new CognitoCachingCredentialsProvider(context, config)) is deprecated

Created on 16 May 2019  路  4Comments  路  Source: aws-amplify/aws-sdk-android

Hey, should I use 'CredentialsProvider' with my secret key in my live application?

Anyone can decompile the APK and get my secret and access keys,
What is the right way to initialize the s3 client and use the s3 bucket storage?
Even in AWS documentation, the deprecated method is mentioned. Please guide.

Right now I am using:

AWSConfiguration config = new AWSConfiguration(context); transferUtility = TransferUtility.builder() .context(context) .awsConfiguration(config) .s3Client(new AmazonS3Client(new CognitoCachingCredentialsProvider(context, config))) .build();

By using this crash occurs on mostly KitKat devices:

Caused by java.lang.IllegalArgumentException TransferUtility has not been configured with a default bucket. Please use the corresponding method that specifies the bucket name or configure the default bucket name in construction of the object. See TransferUtility.builder().defaultBucket() or TransferUtility.builder().awsConfiguration()

But if I use this:

BasicAWSCredentials awsCreds = new BasicAWSCredentials("access_key_id", "secret_key_id"); AmazonS3Client s3Client = new AmazonS3Client(awsCreds, Region.getRegion(Regions.US_EAST_2));
Anyone can decompile the APK and get my secret and access keys.

What is the exact right way to use Transfer Utility and initializing the s3 client?

@kvasukib sir please see this.

Core S3 Usage Question

Most helpful comment

@mbk820 Your concern is valid. I would recommend you to use Amazon Cognito Identity Pools which retrieves a set of temporary credentials (AWS Access and Secret Access Keys) that are valid for an hour and the SDK retrieves new credentials after the expiration.

AWSConfiguration awsConfiguration = new AWSConfiguration(getApplicationContext());
CognitoCachingCredentialsProvider awsCreds = new CognitoCachingCredentialsProvider(getApplicationContext(), awsConfiguration);
AmazonS3Client s3Client = new AmazonS3Client(awsCreds, Region.getRegion(Regions.US_EAST_2));

TransferUtility transferUtility  = TransferUtility.builder()
    .context(getApplicationContext())
    .awsConfiguration(awsConfiguration)
    .s3Client(s3Client)
    .build();

Take a look at our documentation for more details: https://aws-amplify.github.io/docs/android/storage

All 4 comments

@mbk820 Your concern is valid. I would recommend you to use Amazon Cognito Identity Pools which retrieves a set of temporary credentials (AWS Access and Secret Access Keys) that are valid for an hour and the SDK retrieves new credentials after the expiration.

AWSConfiguration awsConfiguration = new AWSConfiguration(getApplicationContext());
CognitoCachingCredentialsProvider awsCreds = new CognitoCachingCredentialsProvider(getApplicationContext(), awsConfiguration);
AmazonS3Client s3Client = new AmazonS3Client(awsCreds, Region.getRegion(Regions.US_EAST_2));

TransferUtility transferUtility  = TransferUtility.builder()
    .context(getApplicationContext())
    .awsConfiguration(awsConfiguration)
    .s3Client(s3Client)
    .build();

Take a look at our documentation for more details: https://aws-amplify.github.io/docs/android/storage

@kvasukib Hi dear, Hope you are fine, We are using s3 paid services, Our app is live with a lot of users, our users are facing ANRs while initializing 'CognitoCachingCredentialsProvider' and creating 'TransferUtility' object, and some other ANRs, all are related AWS. We have to load a lot of images from s3 storage at runtime while the user scrolling the recycle view.

This is ANR stats, Please give some time, and provide a solution.

`
"main" prio=5 tid=1 Native
| group="main" sCount=1 dsCount=0 flags=1 obj=0x74b64f70 self=0xadabb000
| sysTid=1445 nice=-10 cgrp=default sched=0/0 handle=0xb2136494
| state=S schedstat=( 5851335831 555704094 4259 ) utm=467 stm=116 core=5 HZ=100
| stack=0xbe09b000-0xbe09d000 stackSize=8MB
| held mutexes=
#00 pc 000000000005377c /system/lib/libc.so (__ioctl+8)
#01 pc 00000000000219f3 /system/lib/libc.so (ioctl+30)
#02 pc 000000000003d451 /system/lib/libbinder.so (android::IPCThreadState::talkWithDriver(bool)+168)
#03 pc 000000000003ddff /system/lib/libbinder.so (android::IPCThreadState::waitForResponse(android::Parcel, int)+26)
#04 pc 00000000000371bd /system/lib/libbinder.so (android::BpBinder::transact(unsigned int, android::Parcel const&, android::Parcel, unsigned int)+36)
#05 pc 00000000000c3fe7 /system/lib/libandroid_runtime.so (android_os_BinderProxy_transact(_JNIEnv
, _jobject, int, _jobject, _jobject*, int)+82)
at android.os.BinderProxy.transactNative (Native method)
at android.os.BinderProxy.transact (Binder.java:1136)
at android.security.IKeystoreService$Stub$Proxy.finish (IKeystoreService.java:1404)
at android.security.KeyStore.finish (KeyStore.java:581)
at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer$MainDataStream.finish (KeyStoreCryptoOperationChunkedStreamer.java:338)
at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal (KeyStoreCryptoOperationChunkedStreamer.java:220)
at android.security.keystore.AndroidKeyStoreAuthenticatedAESCipherSpi$BufferAllOutputUntilDoFinalStreamer.doFinal (AndroidKeyStoreAuthenticatedAESCipherSpi.java:373)
at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal (AndroidKeyStoreCipherSpiBase.java:506)
at javax.crypto.Cipher.doFinal (Cipher.java:2055)
at com.amazonaws.internal.keyvaluestore.AWSKeyValueStore.decrypt (AWSKeyValueStore.java:360)
at com.amazonaws.internal.keyvaluestore.AWSKeyValueStore.get (AWSKeyValueStore.java:207)

  • locked <0x018d2329> (a com.amazonaws.internal.keyvaluestore.AWSKeyValueStore)
    at com.amazonaws.auth.CognitoCachingCredentialsProvider.loadCachedCredentials (CognitoCachingCredentialsProvider.java:606)
    at com.amazonaws.auth.CognitoCachingCredentialsProvider.initialize (CognitoCachingCredentialsProvider.java:430)
    at com.amazonaws.auth.CognitoCachingCredentialsProvider. (CognitoCachingCredentialsProvider.java:230)
    at com.example.yasir.logomakerwithcollageview.Templates.S3Downloader. (S3Downloader.java:55)
    at com.example.yasir.logomakerwithcollageview.Templates.TemplatesCatSubAdapter. (TemplatesCatSubAdapter.java:111)
    at com.example.yasir.logomakerwithcollageview.Templates.TemplatesCatsAdapter.onBindViewHolder (TemplatesCatsAdapter.java:177)
    at com.example.yasir.logomakerwithcollageview.Templates.TemplatesCatsAdapter.onBindViewHolder (TemplatesCatsAdapter.java:27)
    at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder (RecyclerView.java:6673)
    at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder (RecyclerView.java:6714)
    at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline (RecyclerView.java:5647)
    at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline (RecyclerView.java:5913)
    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:5752)
    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:5748)
    at android.support.v7.widget.LinearLayoutManager$LayoutState.next (LinearLayoutManager.java:2232)
    at android.support.v7.widget.LinearLayoutManager.layoutChunk (LinearLayoutManager.java:1559)
    at android.support.v7.widget.LinearLayoutManager.fill (LinearLayoutManager.java:1519)
    at android.support.v7.widget.LinearLayoutManager.scrollBy (LinearLayoutManager.java:1333)
    at android.support.v7.widget.LinearLayoutManager.scrollVerticallyBy (LinearLayoutManager.java:1077)
    at android.support.v7.widget.RecyclerView.scrollByInternal (RecyclerView.java:1815)
    at android.support.v7.widget.RecyclerView.onTouchEvent (RecyclerView.java:3076)
    at android.view.View.dispatchTouchEvent (View.java:12516)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3026)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2705)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3032)
    at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2719)
    at com.android.internal.policy.DecorView.superDispatchTouchEvent (DecorView.java:479)
    at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent (PhoneWindow.java:1836)
    at android.app.Activity.dispatchTouchEvent (Activity.java:3408)
    at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent (WindowCallbackWrapper.java:68)
    at com.android.internal.policy.DecorView.dispatchTouchEvent (DecorView.java:437)
    at android.view.View.dispatchPointerEvent (View.java:12755)
    at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent (ViewRootImpl.java:5151)
    at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess (ViewRootImpl.java:4954)
    at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:4471)
    at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:4524)
    at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:4490)
    at android.view.ViewRootImpl$AsyncInputStage.forward (ViewRootImpl.java:4630)
    at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:4498)
    at android.view.ViewRootImpl$AsyncInputStage.apply (ViewRootImpl.java:4687)
    at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:4471)
    at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:4524)
    at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:4490)
    at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:4498)
    at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:4471)
    at android.view.ViewRootImpl.deliverInputEvent (ViewRootImpl.java:7197)
    at android.view.ViewRootImpl.doProcessInputEvents (ViewRootImpl.java:7131)
    at android.view.ViewRootImpl.enqueueInputEvent (ViewRootImpl.java:7092)
    at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent (ViewRootImpl.java:7300)
    at android.view.InputEventReceiver.dispatchInputEvent (InputEventReceiver.java:193)
    at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents (Native method)
    at android.view.InputEventReceiver.consumeBatchedInputEvents (InputEventReceiver.java:184)
    at android.view.ViewRootImpl.doConsumeBatchedInput (ViewRootImpl.java:7271)
    at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run (ViewRootImpl.java:7323)
    at android.view.Choreographer$CallbackRecord.run (Choreographer.java:949)
    at android.view.Choreographer.doCallbacks (Choreographer.java:761)
    at android.view.Choreographer.doFrame (Choreographer.java:690)
    at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:935)
    at android.os.Handler.handleCallback (Handler.java:873)
    at android.os.Handler.dispatchMessage (Handler.java:99)
    at android.os.Looper.loop (Looper.java:193)
    at android.app.ActivityThread.main (ActivityThread.java:6923)
    at java.lang.reflect.Method.invoke (Native method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:870)
    `

Thanks for the update. @kvasukib Can you make a note of this crash?

@mbk820 Thank you for the bug report. I will track this crash as part of #937 issue. Closing this issue.

Was this page helpful?
0 / 5 - 0 ratings