awslabs / aws-sdk-kotlin

Multiplatform AWS SDK for Kotlin
Apache License 2.0
410 stars 49 forks source link

ProviderConfigurationException #1274

Closed AlihuenSalis closed 7 months ago

AlihuenSalis commented 7 months ago

Describe the bug

When try to list objects from my s3Bucket, i get androidRuntime error because my credentials can't be read from my environment.

Expected behavior

I want to list all the objects in my s3 bucket.

Current behavior

I get this error on my console

Process: com.example.awsskdandroid, PID: 13121 aws.sdk.kotlin.runtime.auth.credentials.ProviderConfigurationException: Missing value for environment variable AWS_ACCESS_KEY_ID at aws.sdk.kotlin.runtime.auth.credentials.EnvironmentCredentialsProvider.requireEnv(EnvironmentCredentialsProvider.kt:32) at aws.sdk.kotlin.runtime.auth.credentials.EnvironmentCredentialsProvider.resolve(EnvironmentCredentialsProvider.kt:39) at aws.smithy.kotlin.runtime.http.operation.AuthHandler.call(SdkOperationExecution.kt:283) at aws.smithy.kotlin.runtime.http.operation.AuthHandler.call(SdkOperationExecution.kt:259) at aws.sdk.kotlin.runtime.http.middleware.AwsRetryHeaderMiddleware.handle(AwsRetryHeaderMiddleware.kt:39) at aws.sdk.kotlin.runtime.http.middleware.AwsRetryHeaderMiddleware.handle(AwsRetryHeaderMiddleware.kt:26) at aws.smithy.kotlin.runtime.io.middleware.DecoratedHandler.call(Middleware.kt:44) at aws.smithy.kotlin.runtime.io.middleware.Phase.handle(Phase.kt:67) at aws.smithy.kotlin.runtime.io.middleware.DecoratedHandler.call(Middleware.kt:44) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware.tryAttempt-BWLJW6A(RetryMiddleware.kt:78) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware.access$tryAttempt-BWLJW6A(RetryMiddleware.kt:31) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware$handle$result$outcome$1$invokeSuspend$$inlined$withSpan$default$1.invokeSuspend(CoroutineContextTraceExt.kt:136) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware$handle$result$outcome$1$invokeSuspend$$inlined$withSpan$default$1.invoke(Unknown Source:8) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware$handle$result$outcome$1$invokeSuspend$$inlined$withSpan$default$1.invoke(Unknown Source:4) at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:78) at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:167) at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware$handle$result$outcome$1.invokeSuspend(RetryMiddleware.kt:134) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware$handle$result$outcome$1.invoke(Unknown Source:8) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware$handle$result$outcome$1.invoke(Unknown Source:2) at aws.smithy.kotlin.runtime.retries.StandardRetryStrategy.doTryLoop(StandardRetryStrategy.kt:60) at aws.smithy.kotlin.runtime.retries.StandardRetryStrategy.retry$suspendImpl(StandardRetryStrategy.kt:40) at aws.smithy.kotlin.runtime.retries.StandardRetryStrategy.retry(Unknown Source:0) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware.handle(RetryMiddleware.kt:46) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware.handle(RetryMiddleware.kt:31) at aws.smithy.kotlin.runtime.io.middleware.DecoratedHandler.call(Middleware.kt:44) at aws.smithy.kotlin.runtime.http.operation.MutateHandler.call(SdkOperationExecution.kt:256) at aws.smithy.kotlin.runtime.http.operation.MutateHandler.call(SdkOperationExecution.kt:253) at aws.smithy.kotlin.runtime.io.middleware.ModifyRequestMiddleware.handle(ModifyRequest.kt:26) at aws.smithy.kotlin.runtime.io.middleware.DecoratedHandler.call(Middleware.kt:44) at aws.smithy.kotlin.runtime.io.middleware.ModifyRequestMiddleware.handle(ModifyRequest.kt:26) at aws.smithy.kotlin.runtime.io.middleware.DecoratedHandler.call(Middleware.kt:44) at aws.smithy.kotlin.runtime.io.middleware.Phase.handle(Phase.kt:67) at aws.smithy.kotlin.runtime.io.middleware.DecoratedHandler.call(Middleware.kt:44) at aws.smithy.kotlin.runtime.http.operation.SerializeHandler.call(SdkOperationExecution.kt:249) at aws.smithy.kotlin.runtime.http.operation.SerializeHandler.call(SdkOperationExecution.kt:231) at aws.smithy.kotlin.runtime.http.operation.InitializeHandler.call(SdkOperationExecution.kt:228) at aws.smithy.kotlin.runtime.io.middleware.Phase.handle(Phase.kt:63)

at aws.smithy.kotlin.runtime.io.middleware.DecoratedHandler.call(Middleware.kt:44) at aws.smithy.kotlin.runtime.http.operation.OperationHandler.call(SdkOperationExecution.kt:208) at aws.smithy.kotlin.runtime.http.operation.OperationHandler.call(SdkOperationExecution.kt:200) at aws.smithy.kotlin.runtime.http.operation.SdkHttpOperationKt$execute$$inlined$withSpan$1.invokeSuspend(CoroutineContextTraceExt.kt:126) at aws.smithy.kotlin.runtime.http.operation.SdkHttpOperationKt$execute$$inlined$withSpan$1.invoke(Unknown Source:8) at aws.smithy.kotlin.runtime.http.operation.SdkHttpOperationKt$execute$$inlined$withSpan$1.invoke(Unknown Source:4) at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:78) at kotlinx.coroutines.BuildersKtBuilders_commonKt.withContext(Builders.common.kt:167) at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1) at aws.smithy.kotlin.runtime.http.operation.SdkHttpOperationKt.execute(SdkHttpOperation.kt:179) at aws.smithy.kotlin.runtime.http.operation.SdkHttpOperationKt.roundTrip(SdkHttpOperation.kt:86) at aws.sdk.kotlin.services.s3.DefaultS3Client.listObjectsV2(DefaultS3Client.kt:2917) at com.example.awsskdandroid.MainActivity.getObjects(MainActivity.kt:74) at com.example.awsskdandroid.MainActivity.access$getObjects(MainActivity.kt:27) at com.example.awsskdandroid.MainActivity$onCreate$2.invokeSuspend(MainActivity.kt:42) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:367) at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30) at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:25) at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110) at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126) at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56) at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1) at kotlinx.coroutines.BuildersKtBuilders_commonKt.launch$default(Builders.common.kt:47) at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1) at com.example.awsskdandroid.MainActivity.onCreate(MainActivity.kt:42) at android.app.Activity.performCreate(Activity.java:8591) at android.app.Activity.performCreate(Activity.java:8570) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4150) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4325) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8762) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@1e15aa9, Dispatchers.Main.immediate]

Steps to Reproduce

  1. Create a android project in android studio with kotlin language.
  2. Import the library " implementation("aws.sdk.kotlin:s3:1.0.0") "
  3. In android studio, i have a aws toolkit in wich i setup authentication with my IAM user.
  4. I get the credentials file with my aws_access_key and aws_secret_access_key and the config file with the region.
  5. In the main activity execute the next code.
    
    import androidx.appcompat.app.AppCompatActivity
    import android.os.Bundle
    import androidx.lifecycle.lifecycleScope
    import aws.sdk.kotlin.runtime.auth.credentials.EnvironmentCredentialsProvider
    import aws.sdk.kotlin.services.s3.S3Client
    import aws.sdk.kotlin.services.s3.model.ListObjectsV2Request
    import kotlinx.coroutines.launch

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main)

      lifecycleScope.launch { getObjects() }

  }

private suspend fun getObjects() {

      val request = ListObjectsV2Request {
          bucket = "bucketName"
      }

     val s3C = S3Client {
          region = "us-east-1"
          credentialsProvider = EnvironmentCredentialsProvider()
      }

      s3C.use { s3 ->
          val response =  s3.listObjectsV2(request)
          response.contents?.forEach { myObject ->
                 println("The name of the key is ${myObject.key}")
          }
      }

} }



### Possible Solution

_No response_

### Context

In command line, with the comand " aws s3api list-objects-v2 --bucket bucketName " i get the correct output. But not programmatically

### AWS Kotlin SDK version used

s3:1.0.0

### Platform (JVM/JS/Native)

JVM

### Operating System and version

macOS Sonoma 14.4.1
ianbotsf commented 7 months ago

Hi @AlihuenSalis, it looks like your code is configured to use EnvironmentCredentialsProvider which searches for credentials in the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. If those env vars are not configured then the credentials resolution will fail. You'll need to either set those env vars or use a different credentials provider, such as ProfileCredentialsProvider which searches for credentials in AWS profile files.

Just FYI: the default credentials provider will check environment variables, JVM system properties, on-host credentials for EC2/Lambda/etc., AWS profile files, and various other locations automatically. To use this default provider, simply don't set the credentialsProvider property in the client initialization block

Does that resolve your issue?

AlihuenSalis commented 7 months ago

Hi. Thanks for your answer. I deleted the line credentialsProvider = EnvironmentCredentialsProvider() from my s3Client but i get another error ):

FATAL EXCEPTION: main Process: com.example.awsskdandroid, PID: 24157 aws.smithy.kotlin.runtime.identity.IdentityProviderException: No identity could be resolved from the chain: CredentialsProviderChain -> SystemPropertyCredentialsProvider -> EnvironmentCredentialsProvider -> ProfileCredentialsProvider -> StsWebIdentityProvider -> EcsCredentialsProvider -> ImdsCredentialsProvider at aws.smithy.kotlin.runtime.identity.IdentityProviderChain$resolve$2$chainException$1.invoke(IdentityProviderChain.kt:37) at aws.smithy.kotlin.runtime.identity.IdentityProviderChain$resolve$2$chainException$1.invoke(IdentityProviderChain.kt:37) at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) at aws.smithy.kotlin.runtime.identity.IdentityProviderChain$resolve$suspendImpl$$inlined$withSpan$default$1.invokeSuspend(CoroutineContextTraceExt.kt:139) at aws.smithy.kotlin.runtime.identity.IdentityProviderChain$resolve$suspendImpl$$inlined$withSpan$default$1.invoke(Unknown Source:8) at aws.smithy.kotlin.runtime.identity.IdentityProviderChain$resolve$suspendImpl$$inlined$withSpan$default$1.invoke(Unknown Source:4) at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:78) at kotlinx.coroutines.BuildersKtBuilders_commonKt.withContext(Builders.common.kt:167) at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1) at aws.smithy.kotlin.runtime.identity.IdentityProviderChain.resolve$suspendImpl(IdentityProviderChain.kt:93) at aws.smithy.kotlin.runtime.identity.IdentityProviderChain.resolve(Unknown Source:0) at aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProviderChain.resolve(CredentialsProviderChain.kt:22) at aws.smithy.kotlin.runtime.identity.IdentityProvider$DefaultImpls.resolve$default(IdentityProvider.kt:22) at aws.smithy.kotlin.runtime.auth.awscredentials.CachedCredentialsProvider$resolve$3.invokeSuspend(CachedCredentialsProvider.kt:63) at aws.smithy.kotlin.runtime.auth.awscredentials.CachedCredentialsProvider$resolve$3.invoke(Unknown Source:8) at aws.smithy.kotlin.runtime.auth.awscredentials.CachedCredentialsProvider$resolve$3.invoke(Unknown Source:2) at aws.smithy.kotlin.runtime.util.CachedValue.getOrLoad(CachedValue.kt:80) at aws.smithy.kotlin.runtime.auth.awscredentials.CachedCredentialsProvider.resolve(CachedCredentialsProvider.kt:61) at aws.sdk.kotlin.runtime.auth.credentials.DefaultChainCredentialsProvider.resolve(DefaultChainCredentialsProvider.kt:74) at aws.sdk.kotlin.runtime.auth.credentials.internal.ManagedCredentialsProvider.resolve(Unknown Source:2) at aws.smithy.kotlin.runtime.http.operation.AuthHandler.call(SdkOperationExecution.kt:283) at aws.smithy.kotlin.runtime.http.operation.AuthHandler.call(SdkOperationExecution.kt:259) at aws.sdk.kotlin.runtime.http.middleware.AwsRetryHeaderMiddleware.handle(AwsRetryHeaderMiddleware.kt:39) at aws.sdk.kotlin.runtime.http.middleware.AwsRetryHeaderMiddleware.handle(AwsRetryHeaderMiddleware.kt:26) at aws.smithy.kotlin.runtime.io.middleware.DecoratedHandler.call(Middleware.kt:44) at aws.smithy.kotlin.runtime.io.middleware.Phase.handle(Phase.kt:67) at aws.smithy.kotlin.runtime.io.middleware.DecoratedHandler.call(Middleware.kt:44) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware.tryAttempt-BWLJW6A(RetryMiddleware.kt:78) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware.access$tryAttempt-BWLJW6A(RetryMiddleware.kt:31) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware$handle$result$outcome$1$invokeSuspend$$inlined$withSpan$default$1.invokeSuspend(CoroutineContextTraceExt.kt:136) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware$handle$result$outcome$1$invokeSuspend$$inlined$withSpan$default$1.invoke(Unknown Source:8) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware$handle$result$outcome$1$invokeSuspend$$inlined$withSpan$default$1.invoke(Unknown Source:4) at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:78) 2024-04-08 21:11:17.495 24157-24157 AndroidRuntime com.example.awsskdandroid E at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:167) at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware$handle$result$outcome$1.invokeSuspend(RetryMiddleware.kt:134) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware$handle$result$outcome$1.invoke(Unknown Source:8) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware$handle$result$outcome$1.invoke(Unknown Source:2) at aws.smithy.kotlin.runtime.retries.StandardRetryStrategy.doTryLoop(StandardRetryStrategy.kt:60) at aws.smithy.kotlin.runtime.retries.StandardRetryStrategy.retry$suspendImpl(StandardRetryStrategy.kt:40) at aws.smithy.kotlin.runtime.retries.StandardRetryStrategy.retry(Unknown Source:0) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware.handle(RetryMiddleware.kt:46) at aws.smithy.kotlin.runtime.http.middleware.RetryMiddleware.handle(RetryMiddleware.kt:31) at aws.smithy.kotlin.runtime.io.middleware.DecoratedHandler.call(Middleware.kt:44) at aws.smithy.kotlin.runtime.http.operation.MutateHandler.call(SdkOperationExecution.kt:256) at aws.smithy.kotlin.runtime.http.operation.MutateHandler.call(SdkOperationExecution.kt:253) at aws.smithy.kotlin.runtime.io.middleware.ModifyRequestMiddleware.handle(ModifyRequest.kt:26) at aws.smithy.kotlin.runtime.io.middleware.DecoratedHandler.call(Middleware.kt:44) at aws.smithy.kotlin.runtime.io.middleware.ModifyRequestMiddleware.handle(ModifyRequest.kt:26) at aws.smithy.kotlin.runtime.io.middleware.DecoratedHandler.call(Middleware.kt:44) at aws.smithy.kotlin.runtime.io.middleware.Phase.handle(Phase.kt:67) at aws.smithy.kotlin.runtime.io.middleware.DecoratedHandler.call(Middleware.kt:44) at aws.smithy.kotlin.runtime.http.operation.SerializeHandler.call(SdkOperationExecution.kt:249) at aws.smithy.kotlin.runtime.http.operation.SerializeHandler.call(SdkOperationExecution.kt:231) at aws.smithy.kotlin.runtime.http.operation.InitializeHandler.call(SdkOperationExecution.kt:228) at aws.smithy.kotlin.runtime.io.middleware.Phase.handle(Phase.kt:63) at aws.smithy.kotlin.runtime.io.middleware.DecoratedHandler.call(Middleware.kt:44) at aws.smithy.kotlin.runtime.http.operation.OperationHandler.call(SdkOperationExecution.kt:208) at aws.smithy.kotlin.runtime.http.operation.OperationHandler.call(SdkOperationExecution.kt:200) at aws.smithy.kotlin.runtime.http.operation.SdkHttpOperationKt$execute$$inlined$withSpan$1.invokeSuspend(CoroutineContextTraceExt.kt:126) at aws.smithy.kotlin.runtime.http.operation.SdkHttpOperationKt$execute$$inlined$withSpan$1.invoke(Unknown Source:8) at aws.smithy.kotlin.runtime.http.operation.SdkHttpOperationKt$execute$$inlined$withSpan$1.invoke(Unknown Source:4) at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:78) at kotlinx.coroutines.BuildersKtBuilders_commonKt.withContext(Builders.common.kt:167) at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1) at aws.smithy.kotlin.runtime.http.operation.SdkHttpOperationKt.execute(SdkHttpOperation.kt:179) at aws.smithy.kotlin.runtime.http.operation.SdkHttpOperationKt.roundTrip(SdkHttpOperation.kt:86) at aws.sdk.kotlin.services.s3.DefaultS3Client.listObjectsV2(DefaultS3Client.kt:2917) at com.example.awsskdandroid.MainActivity.getObjects(MainActivity.kt:73) at com.example.awsskdandroid.MainActivity.access$getObjects(MainActivity.kt:27) at com.example.awsskdandroid.MainActivity$onCreate$1.invokeSuspend(MainActivity.kt:37) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:367) at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30) at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:25) at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110) 2024-04-08 21:11:17.528 24157-24157 AndroidRuntime com.example.awsskdandroid E at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126) at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56) at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1) at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47) at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1) at com.example.awsskdandroid.MainActivity.onCreate(MainActivity.kt:37) at android.app.Activity.performCreate(Activity.java:8591) at android.app.Activity.performCreate(Activity.java:8570) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4150) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4325) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8762) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) Suppressed: aws.sdk.kotlin.runtime.auth.credentials.ProviderConfigurationException: Missing value for system property aws.accessKeyId at aws.sdk.kotlin.runtime.auth.credentials.SystemPropertyCredentialsProvider.requireProperty(SystemPropertyCredentialsProvider.kt:32) at aws.sdk.kotlin.runtime.auth.credentials.SystemPropertyCredentialsProvider.resolve(SystemPropertyCredentialsProvider.kt:39) at aws.smithy.kotlin.runtime.identity.IdentityProviderChain$resolve$suspendImpl$$inlined$withSpan$default$1.invokeSuspend(CoroutineContextTraceExt.kt:136) ... 94 more Suppressed: aws.sdk.kotlin.runtime.auth.credentials.ProviderConfigurationException: Missing value for environment variable AWS_ACCESS_KEY_ID at aws.sdk.kotlin.runtime.auth.credentials.EnvironmentCredentialsProvider.requireEnv(EnvironmentCredentialsProvider.kt:32) at aws.sdk.kotlin.runtime.auth.credentials.EnvironmentCredentialsProvider.resolve(EnvironmentCredentialsProvider.kt:39) at aws.smithy.kotlin.runtime.identity.IdentityProviderChain$resolve$suspendImpl$$inlined$withSpan$default$1.invokeSuspend(CoroutineContextTraceExt.kt:136) ... 94 more Suppressed: aws.sdk.kotlin.runtime.auth.credentials.ProviderConfigurationException: could not find source profile default at aws.sdk.kotlin.runtime.auth.credentials.profile.ProfileChain$Companion.resolve$aws_config(ProfileChain.kt:323) at aws.sdk.kotlin.runtime.auth.credentials.ProfileCredentialsProvider.resolve(ProfileCredentialsProvider.kt:102) at aws.sdk.kotlin.runtime.auth.credentials.ProfileCredentialsProvider$resolve$1.invokeSuspend(Unknown Source:15) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.UndispatchedCoroutine.afterResume(CoroutineContext.kt:270) at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) ... 6 more Suppressed: aws.sdk.kotlin.runtime.auth.credentials.ProviderConfigurationException: Required field roleArn could not be automatically inferred for StsWebIdentityCredentialsProvider. Either explicitly pass a value, set the environment variable AWS_ROLE_ARN, or set the JVM system property aws.roleArn at aws.sdk.kotlin.runtime.auth.credentials.StsWebIdentityCredentialsProvider$Companion.fromEnvironment-TUY-ock(StsWebIdentityCredentialsProvider.kt:193) at aws.sdk.kotlin.runtime.auth.credentials.StsWebIdentityCredentialsProvider$Companion.fromEnvironment-TUY-ock$default(StsWebIdentityCredentialsProvider.kt:90) at aws.sdk.kotlin.runtime.auth.credentials.StsWebIdentityProvider.resolve(DefaultChainCredentialsProvider.kt:93) at aws.smithy.kotlin.runtime.identity.IdentityProviderChain$resolve$suspendImpl$$inlined$withSpan$default$1.invokeSuspend(CoroutineContextTraceExt.kt:136) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.UndispatchedCoroutine.afterResume(CoroutineContext.kt:270) at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) ... 6 more Suppressed: aws.sdk.kotlin.runtime.auth.credentials.ProviderConfigurationException: Container credentials URI not set at aws.sdk.kotlin.runtime.auth.credentials.EcsCredentialsProvider.resolve(EcsCredentialsProvider.kt:82) at aws.smithy.kotlin.runtime.identity.IdentityProviderChain$resolve$suspendImpl$$inlined$withSpan$default$1.invokeSuspend(CoroutineContextTraceExt.kt:136) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.UndispatchedCoroutine.afterResume(CoroutineContext.kt:270) at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) ... 6 more Suppressed: aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProviderException: failed to load instance profile at aws.sdk.kotlin.runtime.auth.credentials.ImdsCredentialsProvider.resolve(ImdsCredentialsProvider.kt:83) at aws.sdk.kotlin.runtime.auth.credentials.ImdsCredentialsProvider$resolve$1.invokeSuspend(Unknown Source:15) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.UndispatchedCoroutine.afterResume(CoroutineContext.kt:270) at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46) at kotlinx.coroutines.UndispatchedCoroutine.afterResume(CoroutineContext.kt:270) at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) ... 6 more Caused by: aws.smithy.kotlin.runtime.http.HttpException: java.net.SocketTimeoutException: failed to connect to /169.254.169.254 (port 80) from /100.95.201.133 (port 59118) after 2000ms; HttpErrorCode(CONNECT_TIMEOUT) at aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpEngine.roundTrip(OkHttpEngine.kt:158) at aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpEngine$roundTrip$1.invokeSuspend(Unknown Source:15) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793) 2024-04-08 21:11:17.559 24157-24157 AndroidRuntime com.example.awsskdandroid E at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684) Caused by: java.net.SocketTimeoutException: failed to connect to /169.254.169.254 (port 80) from /100.95.201.133 (port 59118) after 2000ms at libcore.io.IoBridge.connectErrno(IoBridge.java:235) at libcore.io.IoBridge.connect(IoBridge.java:179) at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:142) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:390) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436) at java.net.Socket.connect(Socket.java:646) at okhttp3.internal.platform.Platform.connectSocket(Platform.kt:128) at okhttp3.internal.connection.ConnectPlan.connectSocket(ConnectPlan.kt:254) at okhttp3.internal.connection.ConnectPlan.connectTcp(ConnectPlan.kt:128) at okhttp3.internal.connection.FastFallbackExchangeFinder$launchTcpConnect$1.runOnce(FastFallbackExchangeFinder.kt:138) at okhttp3.internal.concurrent.TaskRunner.runTask(TaskRunner.kt:117) at okhttp3.internal.concurrent.TaskRunner.access$runTask(TaskRunner.kt:42) at okhttp3.internal.concurrent.TaskRunner$runnable$1.run(TaskRunner.kt:66) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at java.lang.Thread.run(Thread.java:1012) Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@8691c0, Dispatchers.Main.immediate]

Can you helpme with this ? Thanks.

AlihuenSalis commented 7 months ago

Also i tried with credentialProvider = ProfileCredentialsprovider() in my s3Client, but i get this error:

aws.sdk.kotlin.runtime.auth.credentials.ProviderConfigurationException: could not find source profile default at aws.sdk.kotlin.runtime.auth.credentials.profile.ProfileChain$Companion.resolve$aws_config(ProfileChain.kt:323)

lauzadis commented 7 months ago

Does your AWS config file (likely ~/.aws/config) have a [default] profile configured? Based on what you've written so far, I think you want to have this file structure:

~/.aws/config

[default]
region = <your_region>

~/.aws/credentials

[default]
access_key_id = <your_access_key_id>
secret_access_key = <your_secret_access_key>

If you agree, make sure your files are set up in this manner and then try again, either with credentialsProvider = ProfileCredentialsProvider() or by not configuring any credentials provider (the default credentials provider chain checks the profile).

See the AWS configuration documentation for more information. https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html

AlihuenSalis commented 7 months ago

Yes, all is configured like you show me. I add sample images.

Config-file Credentials-file

both files saved in ~/.aws/config and ~/.aws/credentials

but i get the same error ):

image

ianbotsf commented 7 months ago

Hmm, that is strange. I'd expect if the ~/.aws/config and ~/.aws/credentials files are written as your pictures show then the SDK should be able to find the default profile.

A few sanity checks:

AlihuenSalis commented 7 months ago

Hi. It's really strange. my files ~/.aws/config and ~/.aws/credentials are especifically in Users/myUser/.aws/config and Users/myUser/.aws/credentials and now i changed the profile name "default" to "myUser" in the fiels credentials and config in android studio, but the problem persist ):

I running the project in my physical phone.. but i tried with the emulator but the error is the same ):

It's strange because by command line (aws s3api list-objects-v2 --bucket bucketName) i get the result.

Answering to your question "Is that emulator using the same user/filesystem where you configured the profile?" I don't know, I don't know how to find the file system where my emulator is running to show you

Sorry, but for now i can't fix the error ):

In additional a this info i can tell you that: I'm using this version of the sdk -> implementation("aws.sdk.kotlin:s3:1.0.0"), and my JVM is the version 8 -> JavaVersion.VERSION_1_8

ianbotsf commented 7 months ago

I presume when you're running the AWS CLI and successfully see a result, you're running that on your development machine? If so, then the CLI is using a different environment than your application running on your phone or an emulator. The SDK will not copy user profiles into your application code or deploy them as part of an Android application since they're intended be scoped to your local user. You may be able to confirm this by adding code to your application which attempts to read ~/.aws/config or ~/.aws/credentials when your code is running on your phone/emulator.

Given that the credentials are behaving correctly given their runtime environment, I'm going to resolve this issue. Feel free to open a new issue if you find that credentials providers are not respecting their configuration sources.

Choosing which credentials provider to use will depend on your use case but will almost certainly want to take into account the different users which could be running the application. I suggest you consult the AWS SDKs and Tools reference guide on Authentication and access.

github-actions[bot] commented 7 months ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.