Latest version: 1.0.2
This library requieres Java JDK 21 to compile.
This library includes a few helpers/wrappers like:
- Open ports to an instance.
- Get an instance by tag name.
- List instances by tag name.
- Add/update/remove rules for a security group.
openEC2Ports(String,String):void
Open an EC2 instance firewall (ip range, protocols) for our IP.getInstance(String):<Instance>
Get an EC2 instance by instance Id.getListOfInstanceNames(String):List<String>
Gets list of EC2 instance names by tag name.getSecurityGroupList(String):List<String>
Gets the security group list of an EC2 instance by id.addEC2SecurityGroupRule(String,String,String):void
Add a new rule to an EC2 security group.removeEC2SecurityGroupRule(String,String):void
Remove a rule from an EC2 security group.getIpPermission(String,String):Optional<IpPermission>
Gets the ip permissions of a rule in a security group by its description.updateEC2SecurityGroupRule(String,String,String):void
Update a rule in an EC2 security group.updateEC2SecurityGroupRule(String,String,String,String):void
Update a rule in an EC2 security group.updateSecurityGroupRuleWithMyIp(String,String):void
Update a rule in a security group our ip.getIpFromAws():void
Get the public IP for this computer (using the CheckIP AWS endpoint).
An example:
//Open the firewall to our IP.
AwsUtils.openEC2Ports("instance-name","rule-name");
There are two ways to include the library using maven: a local download, or add the Github Packages maven repo to your m2 settings file.
clone this repo and then and run:
mvn install
This will install the jar in your local maven repository.
add the following configuration to your local maven settings.xml
file (usually located in $HOME/.m2/settings.xml
)
<servers>
<server>
<id>github-public</id>
<username>adriandeleon</username>
<!-- Public token with `read:packages` scope -->
<password>
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
</password>
</server>
</servers>
Once you added the jar to your local maven repository or added the remote Github Packages maven repo, then you can add
this to your pom.xml
file:
First, add this to your <repository>
stanza:
<repositories>
<!--https://github.com/orgs/community/discussions/25629#discussioncomment-3248525-->
<!--https://github.com/orgs/community/discussions/26634-->
<repository>
<id>github-public</id>
<name>adriandeleon's Github Packages maven repository</name>
<url>https://maven.pkg.github.com/adriandeleon/*</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
Then you can add the dependency to your <dependencies>
stanza:
<dependency>
<groupId>me.adriandeleon</groupId>
<artifactId>aws-utils</artifactId>
<version>1.0.2</version>
</dependency>
Note:
You should have a valid $HOME/.aws/config
file
and the AWS_REGION
environment variable set for this library to work.
If you plan on running the integration tests, you will need to set a valid config file (see above), and export the following environment variables first:
AWSUTILS_TEST_VALID_INSTANCE_TAG_NAME
AWSUTILS_TEST_VALID_INSTANCE_ID
AWS_REGION
These should correspond to a valid instance tag name and a valid instanceId on the AWS account that you will run the integration tests against.