Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8990229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:27:23+00:00 2026-06-15T22:27:23+00:00

The motivation here is to create a way to query my AWS environment for

  • 0

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:27:24+00:00Added an answer on June 15, 2026 at 10:27 pm

    You can get the security group list with describeSecurityGroup on an AmazonEC2 client object (whose instance is called ec2 in my example).

    public List<SecurityGroup> findAllSecurityGroups() {
        DescribeSecurityGroupsRequest securityRequest = new DescribeSecurityGroupsRequest();
        DescribeSecurityGroupsResult securityDescription = ec2.describeSecurityGroups(securityRequest);
        return securityDescription.getSecurityGroups();
    }
    

    Once you’ve a securityGroup, you can call securityGroup.getIpPermissions(), which gives you a List<IpPermission>.

    You can check the Javadoc for details, in particular about IpPermission.

    To give you an idea, a toString() representation of the IpPermission rule allowing a server to be contacted on port 80 by any IP, is the following:

    {IpProtocol: tcp, FromPort: 80, ToPort: 80, IpRanges: [0.0.0.0/0], }
    

    If you’re interested only in a particular security group, you can use:

    public SecurityGroup findOneSecurityGroupByName(String securityGroupName) {
        DescribeSecurityGroupsRequest securityRequest = new DescribeSecurityGroupsRequest();
        securityRequest.setGroupNames(Arrays.asList(securityGroupName));
        DescribeSecurityGroupsResult securityDescription = ec2.describeSecurityGroups(securityRequest);
        return securityDescription.getSecurityGroups().get(0);
    }
    

    Some basic integration tests, that should work in any Amazon EC2 account.

    @Test
    public void findsAllSecurityGroups() {
        assertThat(firewall.findAllSecurityGroups().size(), is(greaterThan(0)));
    }
    
    @Test
    public void findsDefaultSecurityGroupByName() {
        SecurityGroup defaultGroup = firewall.findOneSecurityGroupByName("default");
        assertThat(defaultGroup.getGroupName(), is(equalTo("default")));
    }
    
    @Test(expected = AmazonServiceException.class)
    public void throwsExceptionWhenfindingNonExistentSecurityGroup() {
        firewall.findOneSecurityGroupByName("inexistent");
    }
    

    Where firewall is an instance of the class that contains findOneSecurityGroupByName and findsAllSecurityGroups.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My motivation for chaining my class constructors here is so that I have a
Motivation: I have fxcop integrated in the build process, which makes fxcopcmd.exe run each
Motivation Recently I searched for a way to initialize a complex object without passing
motivation: I would like to create a utility class so that instead of having
So here is my basic motivation for my question obfuscated a little: I want
Is there a way in .NET to create a type derived from decimal that
My motivation for the augmentation of Object is I want to be able to
Edit: Here's a truly simple example. Motivation for this example below. This compiles: {-#
Motivation : I often want to paste the results of a quick analysis using
Motivation To utilize Selenium's CSS selector mechanism alongside with CSS attribute selectors and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.