com.amazonaws.services.ec2.model.CreateSecurityGroupResult Java Examples
The following examples show how to use
com.amazonaws.services.ec2.model.CreateSecurityGroupResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VpcImpl.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
@Override public SecurityGroup createSecurityGroup(CreateSecurityGroupRequest request, ResultCapture<CreateSecurityGroupResult> extractor) { ActionResult result = resource.performAction("CreateSecurityGroup", request, extractor); if (result == null) return null; return new SecurityGroupImpl(result.getResource()); }
Example #2
Source File: EC2Impl.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
@Override public SecurityGroup createSecurityGroup(CreateSecurityGroupRequest request, ResultCapture<CreateSecurityGroupResult> extractor) { ActionResult result = service.performAction("CreateSecurityGroup", request, extractor); if (result == null) return null; return new SecurityGroupImpl(result.getResource()); }
Example #3
Source File: EC2Impl.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
@Override public SecurityGroup createSecurityGroup(String description, String groupName) { return createSecurityGroup(description, groupName, (ResultCapture<CreateSecurityGroupResult>)null); }
Example #4
Source File: EC2Impl.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
@Override public SecurityGroup createSecurityGroup(String description, String groupName, ResultCapture<CreateSecurityGroupResult> extractor) { CreateSecurityGroupRequest request = new CreateSecurityGroupRequest() .withDescription(description) .withGroupName(groupName); return createSecurityGroup(request, extractor); }
Example #5
Source File: AmazonIpRuleManager.java From usergrid with Apache License 2.0 | 5 votes |
@Override public boolean createRuleSet( final String name ) { try { CreateSecurityGroupRequest request = new CreateSecurityGroupRequest(); request = request.withGroupName( name ).withDescription( "Judo Chop Security Group" ); CreateSecurityGroupResult result = client.createSecurityGroup( request ); return ( result != null && result.getGroupId() != null && ! result.getGroupId().isEmpty() ); } catch ( AmazonServiceException e ) { LOG.warn( "Error while trying to create security group", e ); return false; } }
Example #6
Source File: BaseTest.java From aws-mock with MIT License | 5 votes |
/** * Create Security Group. * * @param groupName the group Name * @param groupDescription the group Description * @param vpcId vpcId for Sg * @return Security Group Id */ protected final String createSecurityGroup(final String groupName, final String groupDescription, final String vpcId) { String groupId = null; CreateSecurityGroupRequest req = new CreateSecurityGroupRequest(); req.setGroupName(groupName); req.setDescription(groupDescription); req.setVpcId(vpcId); CreateSecurityGroupResult result = amazonEC2Client.createSecurityGroup(req); if (result != null) { groupId = result.getGroupId(); } return groupId; }
Example #7
Source File: PublicAccessAutoFix.java From pacbot with Apache License 2.0 | 4 votes |
/** * Creates the security group. * * @param sourceSecurityGroupId the source security group id * @param vpcId the vpc id * @param ec2Client the ec 2 client * @param ipPermissionsToBeAdded the ip permissions to be added * @param resourceId the resource id * @param defaultCidrIp the default cidr ip * @param existingIpPermissions the existing ip permissions * @return the string * @throws Exception the exception */ public static String createSecurityGroup(String sourceSecurityGroupId, String vpcId, AmazonEC2 ec2Client, Collection<IpPermission> ipPermissionsToBeAdded, String resourceId,String defaultCidrIp,List<IpPermission> existingIpPermissions) throws Exception { String createdSecurityGroupId = null; try { CreateSecurityGroupRequest createsgRequest = new CreateSecurityGroupRequest(); createsgRequest.setGroupName(createSecurityGroupName(pacTag,resourceId)); createsgRequest.setVpcId(vpcId); createsgRequest.setDescription(createSecurityGroupDescription(sourceSecurityGroupId)); CreateSecurityGroupResult createResult = ec2Client.createSecurityGroup(createsgRequest); createdSecurityGroupId = createResult.getGroupId(); if (!createdSecurityGroupId.isEmpty()) { logger.info("Security Group {} created successfully" ,createdSecurityGroupId); // Authorize newly created securityGroup with Inbound Rules AuthorizeSecurityGroupIngressRequest authRequest = new AuthorizeSecurityGroupIngressRequest(); authRequest.setGroupId(createdSecurityGroupId); if(ipPermissionsToBeAdded.isEmpty()){ IpRange ipv4Ranges = new IpRange(); ipv4Ranges.setCidrIp(defaultCidrIp); for (IpPermission ipPermission : existingIpPermissions) { if (!ipPermission.getIpv4Ranges().isEmpty()) { ipPermission.setIpv4Ranges(Arrays.asList(ipv4Ranges)); } if (!ipPermission.getIpv6Ranges().isEmpty()) { Ipv6Range ipv6Range = new Ipv6Range(); ipPermission.setIpv6Ranges(Arrays.asList(ipv6Range)); } if (!ipPermission.getIpv4Ranges().isEmpty() || !ipPermission.getIpv6Ranges().isEmpty()) { ipPermissionsToBeAdded.add(ipPermission); } } } authRequest.setIpPermissions(ipPermissionsToBeAdded); ec2Client.authorizeSecurityGroupIngress(authRequest); //adding tag String deleteSgTag = CommonUtils.getPropValue("deleteSgTag"); Map<String, String> tagMap = new HashMap(); tagMap.put(deleteSgTag, "true"); CreateTagsRequest createTagsRequest = new CreateTagsRequest(Arrays.asList(createdSecurityGroupId), new ArrayList<>()); createTagsRequest.setTags(tagMap.entrySet().stream().map(t -> new Tag(t.getKey(), t.getValue())).collect(Collectors.toList())); try { ec2Client.createTags(createTagsRequest); } catch (AmazonServiceException ase) { logger.error("error tagging sg - > " + resourceId, ase); throw ase; } } } catch (Exception e) { logger.error(e.getMessage()); logger.debug(e.getMessage()); throw new RuntimeException(sourceSecurityGroupId+ " SG copy failed"); } return createdSecurityGroupId; }
Example #8
Source File: CreateSecurityGroup.java From aws-doc-sdk-examples with Apache License 2.0 | 4 votes |
public static void main(String[] args) { final String USAGE = "To run this example, supply a group name, group description and vpc id\n" + "Ex: CreateSecurityGroup <group-name> <group-description> <vpc-id>\n"; if (args.length != 3) { System.out.println(USAGE); System.exit(1); } String group_name = args[0]; String group_desc = args[1]; String vpc_id = args[2]; final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient(); CreateSecurityGroupRequest create_request = new CreateSecurityGroupRequest() .withGroupName(group_name) .withDescription(group_desc) .withVpcId(vpc_id); CreateSecurityGroupResult create_response = ec2.createSecurityGroup(create_request); System.out.printf( "Successfully created security group named %s", group_name); IpRange ip_range = new IpRange() .withCidrIp("0.0.0.0/0"); IpPermission ip_perm = new IpPermission() .withIpProtocol("tcp") .withToPort(80) .withFromPort(80) .withIpv4Ranges(ip_range); IpPermission ip_perm2 = new IpPermission() .withIpProtocol("tcp") .withToPort(22) .withFromPort(22) .withIpv4Ranges(ip_range); AuthorizeSecurityGroupIngressRequest auth_request = new AuthorizeSecurityGroupIngressRequest() .withGroupName(group_name) .withIpPermissions(ip_perm, ip_perm2); AuthorizeSecurityGroupIngressResult auth_response = ec2.authorizeSecurityGroupIngress(auth_request); System.out.printf( "Successfully added ingress policy to security group %s", group_name); }
Example #9
Source File: GroupController.java From sequenceiq-samples with Apache License 2.0 | 4 votes |
@RequestMapping(method = RequestMethod.GET, value = {"/group/create"}) @ResponseBody public CreateSecurityGroupResult createSecurityGroup(@RequestParam("name") String name, @RequestParam("description") String description, @RequestParam("accessKey") String accessKey, @RequestParam("secretKey") String secretKey) { return awsec2Service.createSecurityGroup(awsCredentialsFactory.createSimpleAWSCredentials(accessKey, secretKey), name, description); }
Example #10
Source File: Vpc.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * Performs the <code>CreateSecurityGroup</code> action and use a * ResultCapture to retrieve the low-level client response. * * <p> * The following request parameters will be populated from the data of this * <code>Vpc</code> resource, and any conflicting parameter value set in the * request will be overridden: * <ul> * <li> * <b><code>VpcId</code></b> * - mapped from the <code>Id</code> identifier. * </li> * </ul> * * <p> * * @return The <code>SecurityGroup</code> resource object associated with * the result of this action. * @see CreateSecurityGroupRequest */ SecurityGroup createSecurityGroup(CreateSecurityGroupRequest request, ResultCapture<CreateSecurityGroupResult> extractor);
Example #11
Source File: EC2.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * Performs the <code>CreateSecurityGroup</code> action and use a * ResultCapture to retrieve the low-level client response. * * <p> * * @return The <code>SecurityGroup</code> resource object associated with * the result of this action. * @see CreateSecurityGroupRequest */ com.amazonaws.resources.ec2.SecurityGroup createSecurityGroup( CreateSecurityGroupRequest request, ResultCapture<CreateSecurityGroupResult> extractor);
Example #12
Source File: EC2.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * The convenient method form for the <code>CreateSecurityGroup</code> * action. * * @see #createSecurityGroup(CreateSecurityGroupRequest, ResultCapture) */ com.amazonaws.resources.ec2.SecurityGroup createSecurityGroup(String description, String groupName, ResultCapture<CreateSecurityGroupResult> extractor);
Example #13
Source File: SecurityGroupService.java From sequenceiq-samples with Apache License 2.0 | votes |
CreateSecurityGroupResult createSecurityGroup(AWSCredentials credentials, String groupName, String description);