Describe the bug
I think that #7196 did not get fixed all the way.
Long story short, when creating an AutoScalingClient using its builder, if I set credentialsProvider() to be ProfileCredentialsProvider.create("davidprofile"), it will still attempt to fetch the region from the default profile, rather than davidprofile, which does contain the region.
Regression Issue
Expected Behavior
The expected behaviour is that, if the profile contains a region, then it should be used. I confirmed that the profile in question absolutely contains the region, located in ~/.aws/config. The entry is like so.
[profile davidprofile]
login_session = arn:aws:sts::MY_ACCOUNT_ID:assumed-role/MY_ROLE/MY_USERNAME
region = us-east-2
Current Behavior
It keeps attempting to grab the region from the default profile. Since I have nothing set in the default profile, I get an error, saying it can't find the region from any region provider on the default chain.
Here is the stacktrace.
Exception in thread "AWT-EventQueue-0" software.amazon.awssdk.core.exception.SdkClientException: Unable to load region from any of the providers in the chain software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain@2402e603: [software.amazon.awssdk.regions.providers.SystemSettingsRegionProvider@10d30bf6: Unable to load region from system settings. Region must be specified either via environment variable (AWS_REGION) or system property (aws.region)., software.amazon.awssdk.regions.providers.AwsProfileRegionProvider@1f1dbf7: No region provided in profile: default, software.amazon.awssdk.regions.providers.InstanceProfileRegionProvider@5b07dee8: Unable to contact EC2 metadata service.]
at software.amazon.awssdk.core.exception.SdkClientException$BuilderImpl.build(SdkClientException.java:130)
at software.amazon.awssdk.regions.providers.AwsRegionProviderChain.getRegion(AwsRegionProviderChain.java:70)
at software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder.resolveRegion(AwsDefaultClientBuilder.java:375)
at software.amazon.awssdk.utils.AttributeMap$DerivedValue.primeCache(AttributeMap.java:604)
at software.amazon.awssdk.utils.AttributeMap$DerivedValue.get(AttributeMap.java:593)
at software.amazon.awssdk.utils.AttributeMap$Builder.resolveValue(AttributeMap.java:400)
at software.amazon.awssdk.utils.AttributeMap$Builder.internalGet(AttributeMap.java:389)
at software.amazon.awssdk.utils.AttributeMap$Builder.access$1300(AttributeMap.java:201)
at software.amazon.awssdk.utils.AttributeMap$Builder$1.get(AttributeMap.java:403)
at software.amazon.awssdk.services.autoscaling.DefaultAutoScalingBaseClientBuilder.lambda$finalizeServiceConfiguration$2(DefaultAutoScalingBaseClientBuilder.java:106)
at software.amazon.awssdk.utils.AttributeMap$DerivedValue.primeCache(AttributeMap.java:604)
at software.amazon.awssdk.utils.AttributeMap$DerivedValue.get(AttributeMap.java:593)
at software.amazon.awssdk.utils.AttributeMap$Builder.resolveValue(AttributeMap.java:400)
at software.amazon.awssdk.utils.AttributeMap$Builder.internalComputeIfAbsent(AttributeMap.java:331)
at software.amazon.awssdk.utils.AttributeMap$Builder.putLazyIfAbsent(AttributeMap.java:275)
at software.amazon.awssdk.core.client.config.SdkClientConfiguration$Builder.lazyOptionIfAbsent(SdkClientConfiguration.java:182)
at software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder.finalizeAwsConfiguration(AwsDefaultClientBuilder.java:191)
at software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder.finalizeChildConfiguration(AwsDefaultClientBuilder.java:173)
at software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.syncClientConfiguration(SdkDefaultClientBuilder.java:206)
at software.amazon.awssdk.services.autoscaling.DefaultAutoScalingClientBuilder.buildClient(DefaultAutoScalingClientBuilder.java:37)
at software.amazon.awssdk.services.autoscaling.DefaultAutoScalingClientBuilder.buildClient(DefaultAutoScalingClientBuilder.java:25)
at software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.build(SdkDefaultClientBuilder.java:173)
at AutoScalingHealthCheck.lambda$main$0(AutoScalingHealthCheck.java:134)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:323)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:714)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Reproduction Steps
Long story short, the following code should be able to get the region from the profile for davidprofile, but it does not.
import module java.base;
import java.util.List;
import software.amazon.awssdk.auth.credentials.*;
import software.amazon.awssdk.regions.*;
import software.amazon.awssdk.services.autoscaling.*;
import software.amazon.awssdk.services.autoscaling.model.*;
void main() throws Exception
{
try
(
final AutoScalingClient asgClient =
AutoScalingClient
.builder()
.credentialsProvider
(
ProfileCredentialsProvider.create("davidprofile")
)
//.region(Region.US_EAST_2) //should not be needed, contained in the profile
.build()
)
{
final List<AutoScalingGroup> results =
asgClient
.describeAutoScalingGroupsPaginator()
.autoScalingGroups()
.stream()
.filter(_ -> true) //removed filter logic
.toList()
;
}
}
Here is a simple reproducer.
- Using AWS CLI, do
aws login --profile davidprofile.
- During the login, you will be prompted for region -- select
us-east-2.
- Upon logging in, run the above java code.
- You should see an exception about not being able to fetch the region from any of the region providers.
I set the dependency as 2.51.1. If you do Ctrl+F for "AWS-Sign-In-Service", you will see that fix
Possible Solution
Sadly, not sure. This is my first bug submission for aws.
Additional Information/Context
Well, #7196 looks like it attempted to fix this issue, but still doesn't for my example.
AWS Java SDK version used
2.51.1
JDK version used
26.0.1
Operating System and version
Windows 11 Enterprise (OS build 22631.7376)
Describe the bug
I think that #7196 did not get fixed all the way.
Long story short, when creating an
AutoScalingClientusing its builder, if I setcredentialsProvider()to beProfileCredentialsProvider.create("davidprofile"), it will still attempt to fetch the region from the default profile, rather thandavidprofile, which does contain the region.Regression Issue
Expected Behavior
The expected behaviour is that, if the profile contains a region, then it should be used. I confirmed that the profile in question absolutely contains the region, located in ~/.aws/config. The entry is like so.
Current Behavior
It keeps attempting to grab the region from the default profile. Since I have nothing set in the default profile, I get an error, saying it can't find the region from any region provider on the default chain.
Here is the stacktrace.
Reproduction Steps
Long story short, the following code should be able to get the region from the profile for
davidprofile, but it does not.Here is a simple reproducer.
aws login --profile davidprofile.us-east-2.I set the dependency as 2.51.1. If you do Ctrl+F for "AWS-Sign-In-Service", you will see that fix
Possible Solution
Sadly, not sure. This is my first bug submission for aws.
Additional Information/Context
Well, #7196 looks like it attempted to fix this issue, but still doesn't for my example.
AWS Java SDK version used
2.51.1
JDK version used
26.0.1
Operating System and version
Windows 11 Enterprise (OS build 22631.7376)