List of usage examples for com.amazonaws.services.rds.model CreateDBSecurityGroupRequest CreateDBSecurityGroupRequest
public CreateDBSecurityGroupRequest(String dBSecurityGroupName, String dBSecurityGroupDescription)
From source file:beanstalk.BeansDatabase.java
License:Apache License
public boolean allowIPConnectionWithDB(String AWSKeyId, String AWSSecretKey, String dbIdentifier) {//throws Exception { boolean ret = false; String security_group = "Cloud4SoaSecGroup"; BasicAWSCredentials basic_credentials = new BasicAWSCredentials(AWSKeyId, AWSSecretKey); AmazonRDSClient rDSClient = new AmazonRDSClient(basic_credentials); //1st step-->add group cloud4soa if not exist CreateDBSecurityGroupRequest create_secGroupRequest = new CreateDBSecurityGroupRequest(security_group, "GroupGeneratedByCloud4SoaAdapter"); DBSecurityGroup securityGroup = new DBSecurityGroup(); try {// w ww . j a v a 2s. com securityGroup = rDSClient.createDBSecurityGroup(create_secGroupRequest); } catch (AmazonClientException amazonClientException) { System.out.print("Error when trying to add Security Group.Security Group might exist already!"); } //2nd step--> add IP to list of specific Security Group AuthorizeDBSecurityGroupIngressRequest ip2SecGroup = new AuthorizeDBSecurityGroupIngressRequest( security_group); //allow specific ip //ip2SecGroup.setCIDRIP("91.132.244.150/5"); //allow everyone ip2SecGroup.setCIDRIP("0.0.0.0/0"); try { rDSClient.authorizeDBSecurityGroupIngress(ip2SecGroup); } catch (AmazonClientException amazonClientException) { System.out.print( "Error when trying to add the specific IP address to the security group.IP might be already entered!"); } return ret; }