Default section with region required in .aws/config
See original GitHub issueI use some profiles with a ProfileCredentialsProvider
to do the SDK operations and my config file has no [default]
section.
Expected Behavior
The region information should be used from the given profile.
Current Behavior
The SDK throws the error:
software.amazon.awssdk.core.exception.SdkClientException: Unable to load region from any of the providers in the chain software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain@11d045b4: [software.amazon.awssdk.regions.providers.SystemSettingsRegionProvider@17e9bc9e: 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@9301672: No region provided in profile: default, software.amazon.awssdk.regions.providers.InstanceProfileRegionProvider@163042ea: Unable to contact EC2 metadata service.]
at software.amazon.awssdk.core.exception.SdkClientException$BuilderImpl.build(SdkClientException.java:97)
at software.amazon.awssdk.regions.providers.AwsRegionProviderChain.getRegion(AwsRegionProviderChain.java:70)
at software.amazon.awssdk.regions.providers.LazyAwsRegionProvider.getRegion(LazyAwsRegionProvider.java:45)
at software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder.regionFromDefaultProvider(AwsDefaultClientBuilder.java:178)
at software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder.resolveRegion(AwsDefaultClientBuilder.java:167)
at software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder.lambda$mergeChildDefaults$0(AwsDefaultClientBuilder.java:111)
at software.amazon.awssdk.utils.builder.SdkBuilder.applyMutation(SdkBuilder.java:61)
at software.amazon.awssdk.core.client.config.SdkClientConfiguration.merge(SdkClientConfiguration.java:66)
at software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder.mergeChildDefaults(AwsDefaultClientBuilder.java:111)
at software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.syncClientConfiguration(SdkDefaultClientBuilder.java:143)
at software.amazon.awssdk.services.ec2.DefaultEc2ClientBuilder.buildClient(DefaultEc2ClientBuilder.java:27)
at software.amazon.awssdk.services.ec2.DefaultEc2ClientBuilder.buildClient(DefaultEc2ClientBuilder.java:22)
at software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.build(SdkDefaultClientBuilder.java:119)
at de.weltraumschaf.aws.DefaultAwsClientFactory.createEc2Client(DefaultAwsClientFactory.java:52)
at de.weltraumschaf.FooTest.createVirtualPrivateCloud(FooTest.java:61)
at de.porsche.zerog.servicebroker.broker.FooTest.foo(FooTest.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
Steps to Reproduce (for bugs)
Remove the [default]
section from the files in ~/.aws
and only add the region
in the particular profiles.
Your Environment
- AWS Java SDK version used: 2.9.20
- JDK version used: JDK 1.8.0_131
- Operating System and version: macOS 10.14.6
Issue Analytics
- State:
- Created 4 years ago
- Comments:18 (7 by maintainers)
Top Results From Across the Web
Set up AWS Credentials and Region for Development
Set the AWS Region in the AWS config file on your local system, located at: ~/.aws/config on Linux, macOS, or Unix. C:\Users\USERNAME\.aws\config on...
Read more >Configuration basics - AWS Command Line Interface
The Default region name identifies the AWS Region whose servers you want to send your requests to by default. This is typically the...
Read more >Configuring the AWS CLI - AWS Command Line Interface
This section explains how to configure the settings that the AWS Command Line Interface (AWS CLI) ... the default output format, and the...
Read more >Configuration and credential file settings - AWS Documentation
The files are divided into profiles . By default, the AWS CLI uses the settings found in the profile named default . To...
Read more >Setting the AWS Region - AWS SDK for JavaScript
A Region is a named set of AWS resources in the same geographical area. An example of a Region is us-east-1 , which...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hm, ok… Maybe I should look into Azure or GCP instead of AWS 😉
You’re configuring the client to use the profile file for credentials, not region. In effect this is what you’re doing:
It’s debatable whether that’s a “good reason” but it’s the reason. The AWS CLI does not have a way to configure credential providers and region providers separately, so that’s not a great example of the Java SDK behaving different than other tools.
If you want behavior equivalent to the AWS CLI, you’ll need to use the
AWS_PROFILE
environment variable or theaws.profile
system property:It’s not ideal, but if you want equivalent behavior, that’s the least amount of code to do it.