aws java sdk ProfileCredentialsProvider without region

97 views Asked by At

AWS S3Client is throwing exception when try to use ProfileCredentialsProvider without region. I've a credentials file that does not have region name but I'm overriding endpoint in the code. I can't hardcode region in the credentials file and considering this I override endpoint without providing the region. Is there a way to create S3Client without region?

ProfileCredentialsProvider credentialsProvider =
                    ProfileCredentialsProvider.builder()
                            .profileFile(profile)
                            .profileName(credentialsProfile)
                            .build();

            return S3Client.builder()
                    .endpointOverride(endpoint) //endpoint is https://s3.ap-south-1.amazonaws.com
                    .credentialsProvider(credentialsProvider)
                    .build();

Getting below error

Failed to connect to S3: Unable to load region from any of the providers in the chain
software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain@62ea3440:
[software.amazon.awssdk.regions.providers.SystemSettingsRegionProvider@4212a0c8: 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@c1bd0be: No region
provided in profile: default, software.amazon.awssdk.regions.providers.InstanceProfileRegionProvider@4bef0fe3: Unable to
contact EC2 metadata service.]

0

There are 0 answers