The motivation here is to create a way to query my AWS environment for a dump of the configuration, serialize it, and then be able to run the query again to see any relevant changes.
I have the group identifiers from:
private List<String> getSecurityGroups(InstanceNetworkInterface netInt) {
List<String> result = new Vector<String>();
List<GroupIdentifier> groups = netInt.getGroups();
for(GroupIdentifier gi : groups) {
result.add(gi.getGroupName());
}
return result;
}
You can get the security group list with
describeSecurityGroupon anAmazonEC2client object (whose instance is calledec2in my example).Once you’ve a
securityGroup, you can callsecurityGroup.getIpPermissions(), which gives you aList<IpPermission>.You can check the Javadoc for details, in particular about IpPermission.
To give you an idea, a
toString()representation of theIpPermissionrule allowing a server to be contacted on port 80 by any IP, is the following:If you’re interested only in a particular security group, you can use:
Some basic integration tests, that should work in any Amazon EC2 account.
Where
firewallis an instance of the class that containsfindOneSecurityGroupByNameandfindsAllSecurityGroups.