Home > Back-end >  Connect to elasticfilesystem.ap-south-1.amazonaws.com:80 failed: Connection refused From Java SDK
Connect to elasticfilesystem.ap-south-1.amazonaws.com:80 failed: Connection refused From Java SDK

Time:07-25

I try to connect Aws EFS using Java Aws sdk. But its Giving Me Error.*

Unable to execute HTTP request: Connect to elasticfilesystem.ap-south-1.amazonaws.com:80 [elasticfilesystem.ap-south-1.amazonaws.com/52.95.85.30] failed: Connection refused

I do not find any example about pragmatically perform operation with Efs. Has there any code example and reference? I try to do something but i am confused i am on right or wrong track. Here i provide my code:

AWSCredentials credentials = new BasicAWSCredentials (
        "*******************",
        "****************************");
ClientConfiguration clientConfig = new ClientConfiguration ();
clientConfig.setProtocol (Protocol.HTTP);
clientConfig.setMaxErrorRetry (DEFAULT_MAX_ERROR_RETRY);
clientConfig.setRetryPolicy (new RetryPolicy (PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION,
        DEFAULT_BACKOFF_STRATEGY, DEFAULT_MAX_ERROR_RETRY, false));

AmazonElasticFileSystem fileSystem = AmazonElasticFileSystemClientBuilder.standard ()
        .withClientConfiguration (clientConfig)
        .withCredentials (new AWSStaticCredentialsProvider (credentials))
        .build ();

CreateFileSystemResult result = fileSystem.createFileSystem (new CreateFileSystemRequest ());
System.out.println (result);

CodePudding user response:

Basically Aws expecting Https protocal and Add region of Builder:

AWSCredentials credentials = new BasicAWSCredentials (
        "*******************",
        "****************************");
ClientConfiguration clientConfig = new ClientConfiguration ();
clientConfig.setProtocol (Protocol.HTTPS); // make it HTTPS
clientConfig.setMaxErrorRetry (DEFAULT_MAX_ERROR_RETRY);
clientConfig.setRetryPolicy (new RetryPolicy (PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION,
        DEFAULT_BACKOFF_STRATEGY, DEFAULT_MAX_ERROR_RETRY, false));

AmazonElasticFileSystem fileSystem = AmazonElasticFileSystemClientBuilder.standard ()
        .withClientConfiguration (clientConfig)
        .withRegion ("ap-south-1") // add region
        .withCredentials (new AWSStaticCredentialsProvider (credentials))
        .build ();

CreateFileSystemResult result = fileSystem.createFileSystem (new CreateFileSystemRequest ());
System.out.println (result);

ITs working for me. I hope it will help others.

  • Related