diff --git a/README.md b/README.md index c4c7c76..23dddd2 100644 --- a/README.md +++ b/README.md @@ -23,17 +23,17 @@ Note: there could be changes to the plugin API. **Settings** -- `dbms.cluster.discovery.resolver_type=EC2-ASG` -- `server.config.strict_validation.enabled=false` : to disable strict settings validation, which will allow the usage of the following plugin-specific settings (You'll still get Warnings : "Unrecognized setting"). +- `discovery.aws.asg_name=` : the name of the Auto-scaling group +- `discovery.aws.region=` : the AWS region hosting the Auto-scaling group (ex: "eu-west-1") -- `dbms.aws.asg_name=` : the name of the Auto-scaling group -- `dbms.aws.region=` : the AWS region hosting the Auto-scaling group (ex: "eu-west-1") -- `dbms.aws.key=` : the Access Key of the user connecting to the AWS API. -- `dbms.aws.secret=` : the Secret Key of the user connecting to the AWS API +Optionally : +- `discovery.aws.key=` : the Access Key of the user connecting to the AWS API. +- `discovery.aws.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. **Permissions** -The AWS User requires the following permissions : +The Role/User requires the following permissions : - "ec2:DescribeInstances", - "autoscaling:DescribeAutoScalingGroups" diff --git a/pom.xml b/pom.xml index 43591a0..6de1ed4 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.neo4j aws-ec2-asg-discovery - 0.1.1 + 0.2.0 17 diff --git a/src/main/java/cs/neo4j/AwsClient.java b/src/main/java/cs/neo4j/AwsClient.java index bd5981b..cb8d33b 100644 --- a/src/main/java/cs/neo4j/AwsClient.java +++ b/src/main/java/cs/neo4j/AwsClient.java @@ -7,6 +7,8 @@ import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; 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.regions.Region; import software.amazon.awssdk.services.autoscaling.AutoScalingClient; import software.amazon.awssdk.services.autoscaling.model.AutoScalingGroup; @@ -18,20 +20,28 @@ public class AwsClient extends LifecycleAdapter { - public static String accessKey; - public static String secretKey; - public static String region; + private static String accessKey; + private static String secretKey; + private static String region; private AutoScalingClient autoScalingClient; private Ec2Client ec2Client; + public AwsClient(String region) { + this.region=region; + createClients(); + } + public AwsClient(String accessKey, String secretKey, String region) { this.accessKey=accessKey; this.secretKey=secretKey; this.region=region; + createClients(); + } + private void createClients(){ this.autoScalingClient = AutoScalingClient.builder() .region(Region.of(region)) .credentialsProvider(awsCredentialsProvider()) @@ -44,7 +54,11 @@ public AwsClient(String accessKey, String secretKey, String region) { } private AwsCredentialsProvider awsCredentialsProvider() { - return () -> AwsBasicCredentials.create(accessKey, secretKey); + if (accessKey != null && secretKey != null) { + return () -> AwsBasicCredentials.create(accessKey, secretKey); + } else { + return InstanceProfileCredentialsProvider.builder().build(); + } } private AutoScalingGroup getAsgByName(String nameSelector) { diff --git a/src/main/java/cs/neo4j/Ec2Settings.java b/src/main/java/cs/neo4j/Ec2Settings.java index 8ea3bef..91dd285 100644 --- a/src/main/java/cs/neo4j/Ec2Settings.java +++ b/src/main/java/cs/neo4j/Ec2Settings.java @@ -18,22 +18,21 @@ public class Ec2Settings implements SettingsDeclaration { @Description("Auto-scaling group name") public static final Setting asg_name = newBuilder( - "dbms.aws.asg_name", STRING, null) + "discovery.aws.asg_name", STRING, null) .build(); @Description("AWS access key") public static final Setting aws_key = newBuilder( - "dbms.aws.key", STRING, null) + "discovery.aws.key", STRING, null) .build(); @Description("AWS secret") public static final Setting aws_secret = newBuilder( - "dbms.aws.secret", STRING, null) + "discovery.aws.secret", STRING, null) .build(); - @Description("AWS region") public static final Setting aws_region = newBuilder( - "dbms.aws.region", STRING, null) + "discovery.aws.region", STRING, null) .build(); }