-
Notifications
You must be signed in to change notification settings - Fork 55
Description
Describe the bug
When running in AgentCore Runtime, the Kotlin SDK (JVM platform) is unable to get AWS credentials from the Default Credentials Chain. Based on a bit of research, I'd say it's a bug in the ImdsCredentialsProvider being unable to work with MicroVM Metadata Service. The equivalent code in the Java SDK (version 2.39.5) works fine
Regression Issue
- Select this option if this issue appears to be a regression.
Expected behavior
AgentCore Runtime uses MicroVM Metadata Service (MMDS) instead of IMDSv2 (https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/security-credentials-management.html), but since the Java SDK works with the IMDS provider, the Kotlin one should behave accordingly
Current behavior
When using the ImdsCredentialsProvider() for getting AWS credentials, it fails to retrieve the IMDS token:
| 2025-11-29T12:07:04.580Z | aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProviderException: failed to load instance profile
| 2025-11-29T12:07:04.580Z | at aws.sdk.kotlin.runtime.auth.credentials.ImdsCredentialsProvider.resolve(ImdsCredentialsProvider.kt:81)
| 2025-11-29T12:07:04.580Z | at aws.sdk.kotlin.runtime.auth.credentials.ImdsCredentialsProvider$resolve$1.invokeSuspend(ImdsCredentialsProvider.kt)
| 2025-11-29T12:07:04.581Z | at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
| 2025-11-29T12:07:04.581Z | at kotlinx.coroutines.UndispatchedCoroutine.afterResume(CoroutineContext.kt:266)
| 2025-11-29T12:07:04.581Z | at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:101)
...
| 2025-11-29T12:07:04.583Z | Caused by: aws.sdk.kotlin.runtime.config.imds.EC2MetadataError: Failed to retrieve IMDS token
| 2025-11-29T12:07:04.583Z | at aws.sdk.kotlin.runtime.config.imds.TokenMiddleware.getToken(TokenMiddleware.kt:80)
| 2025-11-29T12:07:04.583Z | at aws.sdk.kotlin.runtime.config.imds.TokenMiddleware.access$getToken(TokenMiddleware.kt:32)
| 2025-11-29T12:07:04.583Z | at aws.sdk.kotlin.runtime.config.imds.TokenMiddleware$getToken$1.invokeSuspend(TokenMiddleware.kt)
| 2025-11-29T12:07:04.583Z | at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
...
Steps to Reproduce
- Generate a Docker image that runs a JVM application with the Kotlin SDK for AWS. Push it to ECR
- The following code can be used to trigger the error. It can be directly put in the main method
println("Kotlin SDK failing")
runBlocking {
try {
val kotlinClient = BedrockRuntimeClient {
credentialsProvider = ImdsCredentialsProvider()
}
val message = Message {
content = listOf(ContentBlock.Text("Just say hi"))
role = ConversationRole.User
}
val response = kotlinClient.converse {
modelId = "eu.amazon.nova-micro-v1:0"
messages = listOf(message)
}
response.output?.asMessage()?.content?.forEach { println(it) } ?: println("No output message")
kotlinClient.close()
} catch (e: Exception) {
e.printStackTrace()
}
}You can use the following code for checking the Java SDK (beware of imports, you may want to put them in different files or add fully qualified imports)
println("Java SDK working")
try {
val javaClient = BedrockRuntimeClient.builder()
.credentialsProvider(InstanceProfileCredentialsProvider.create())
.build()
val message = Message.builder()
.content(ContentBlock.fromText("Just say hi"))
.role(ConversationRole.USER)
.build()
val request = ConverseRequest.builder()
.modelId("eu.amazon.nova-micro-v1:0")
.messages(message)
.build()
val result = javaClient.converse(request)
result.output().message().content().forEach {
println(it.text())
}
javaClient.close()
} catch (e: Exception) {
e.printStackTrace()
}- Create an AgentCore Runtime agent. Indicate the previously pushed image as the agent source. Specify the authentication to be JWT based. Steps for creating a user and getting its token are described in https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-oauth.html#setup-cognito
- Invoke the agent with cURL and the user token. Steps described in https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-oauth.html#invoke-agent
- Check CloudWatch logs
Possible Solution
No response
Context
Running agents built with Kotlin in AgentCore Runtime
AWS SDK for Kotlin version
1.5.92
Platform (JVM/JS/Native)
JVM
Operating system and version
AgentCore Runtime