Skip to content

Commit

Permalink
0.3.4 make region setting optional
Browse files Browse the repository at this point in the history
  • Loading branch information
pecollet committed Feb 1, 2024
1 parent b89ef97 commit 0213885
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,21 @@ Note: there could be changes to the plugin API.
- `dbms.cluster.discovery.resolver_type=EC2-ASG` : select the discovery protocol implemented by this plugin
- `server.config.strict_validation.enabled=false` : to disable strict settings validation, which will allow the usage of the following plugin-specific settings (You may still get Warnings : "Unrecognized setting").
- `dbms.cluster.discovery.aws.asg_name=<asg_name>` : the name of the Auto-scaling group
- `dbms.cluster.discovery.aws.region=<region>` : the AWS region hosting the Auto-scaling group (ex: "eu-west-1")


Optionally :
- `dbms.cluster.discovery.aws.region=<region>` : the AWS region hosting the Auto-scaling group (ex: "eu-west-1")

If not set, the plugin will attempt to retrieve the region from the VM metadata

- `dbms.cluster.discovery.aws.key=<key>` : the Access Key of the user connecting to the AWS API.
- `dbms.cluster.discovery.aws.secret=<secret>` : the Secret Key of the user connecting to the AWS API.

If not set, the plugin will try to use any InstanceProfile role attached to the EC2 instance. That can be defined in the ASG's LaunchTemplate.

- `dbms.cluster.discovery.aws.address_type=<type>` : type of network address to retrieve from the VM, to use for discovery. One of PRIVATE_IP|PRIVATE_DNSNAME|PUBLIC_IP|PUBLIC_DNSNAME. Defaults to PRIVATE_IP. Must match the type of `server.discovery.advertised_address`.


If not set, the plugin will try to use any InstanceProfile role attached to the EC2 instance. That can be defined in the ASG's LaunchTemplate.

**Permissions**

Expand Down
13 changes: 6 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.neo4j</groupId>
<artifactId>aws-ec2-asg-discovery</artifactId>
<version>0.3.3</version>
<version>0.3.4</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down Expand Up @@ -34,12 +34,11 @@
<version>${neo4j.version}</version>
<scope>provided</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>software.amazon.awssdk</groupId>-->
<!-- <artifactId>aws-core</artifactId>-->
<!-- <version>2.15.7</version>-->
<!--&lt;!&ndash; <scope>provided</scope>&ndash;&gt;-->
<!-- </dependency>-->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>imds</artifactId>
<version>2.23.14</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>autoscaling</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cs/neo4j/AsgResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected void internalInit(Config config, LogService logService, DependencyReso
discoveryPort = checkConfig(config, DiscoverySettings.discovery_listen_address).getPort();

selector = checkConfig(config, Ec2Settings.asg_name);
awsRegion = checkConfig(config, Ec2Settings.aws_region);
awsRegion = config.get(Ec2Settings.aws_region);

awsKey = config.get(Ec2Settings.aws_key);
awsSecret = config.get(Ec2Settings.aws_secret);
Expand Down
35 changes: 26 additions & 9 deletions src/main/java/cs/neo4j/AwsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider;
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.imds.Ec2MetadataClient;
import software.amazon.awssdk.imds.Ec2MetadataResponse;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.autoscaling.AutoScalingClient;
import software.amazon.awssdk.services.autoscaling.model.AutoScalingGroup;
Expand Down Expand Up @@ -45,15 +47,30 @@ public AwsClient(String accessKey, String secretKey, String region, Ec2Settings.
}

private void createClients(){
this.autoScalingClient = AutoScalingClient.builder()
.region(Region.of(region))
.credentialsProvider(awsCredentialsProvider())
.build();

this.ec2Client = Ec2Client.builder()
.region(Region.of(region))
.credentialsProvider(awsCredentialsProvider())
.build();
if (region != null) {
this.autoScalingClient = AutoScalingClient.builder()
.region(Region.of(region))
.credentialsProvider(awsCredentialsProvider())
.build();

this.ec2Client = Ec2Client.builder()
.region(Region.of(region))
.credentialsProvider(awsCredentialsProvider())
.build();
} else {
this.autoScalingClient = AutoScalingClient.builder()
.credentialsProvider(awsCredentialsProvider())
.build();

this.ec2Client = Ec2Client.builder()
.credentialsProvider(awsCredentialsProvider())
.build();
Ec2MetadataClient imdsClient = Ec2MetadataClient.builder()
.build();
Ec2MetadataResponse metadataResponse = imdsClient.get("/latest/meta-data/");
System.out.println(metadataResponse.asString());
}

}

private AwsCredentialsProvider awsCredentialsProvider() {
Expand Down

0 comments on commit 0213885

Please sign in to comment.