Bash script to revoke Inbound rule after some time

0 votes
I have done bash script (bash script + AWS CLI) to assign Inbound rules with IP address for security group in AWS EC2 instances. My team asking me to revoke IP address from security group automatically after two hours. So when allocate new rules ,then it should alive for two hours. Then it should removed from security group. I hope you people understand this question. Kindly reply with solution. Many thanks.
Jul 6 in Other DevOps Questions by Lakshminarayanan
• 1,000 points
94 views

1 answer to this question.

+1 vote

Hi@Lakshminarayanan,

You can find command to remove your ingress rule from the security group. You can use the below-given command in your script file.

$ aws ec2 revoke-security-group-ingress --group-name mygroup --protocol tcp --port 22 --cidr 203.0.113.0/24

Now to automate the script you can use Cron Job concept and schedule your task every two hours.

answered Jul 7 by MD
• 56,480 points
Many thanks @MD. I understand this solution. We can use cron job to revoke inbound rule. But how can i remove exact IP address which is allocated before. Because inbound rules have like Port 22 with IP addresses 1.1.1.1 , 2.2.2.2, 3.3.3.3. The IP address 2.2.2.2 which is assigned before. So i would like to remove this IP. But how can i judge this IP and how to do remove?please reply me bro

I think you can add a description in every rule. When we create any rule, there is an optional option named description. You can remove this based on this.

Yes bro. I will try this method. Once again, Many thanks.

Related Questions In Other DevOps Questions

0 votes
1 answer

How to stop sqlplus command in unix shell script when any sql fails

One idea would be to launch the ...READ MORE

answered Jul 16, 2018 in Other DevOps Questions by Kalgi
• 51,950 points
2,390 views
0 votes
0 answers

How to use version name in Bamboo script

Hi All, We have 3 tasks in our ...READ MORE

Apr 8 in Other DevOps Questions by Abhishek
• 280 points
66 views
0 votes
1 answer

Use vagrant to update $PATH of guest vm

Just try the below script: mvm.vm.provision :shell, :inline ...READ MORE

answered May 1, 2018 in Other DevOps Questions by shubham
• 6,910 points
200 views
0 votes
1 answer

Copy log files to local machines using Jenkins

Try initializing the variables with values according ...READ MORE

answered May 2, 2018 in Other DevOps Questions by ajs3033
• 7,280 points
94 views
0 votes
1 answer

How to get issues count based on rules in a sonar project?

There are API docs in the footer ...READ MORE

answered May 4, 2018 in Other DevOps Questions by DareDev
• 6,850 points
1,049 views
0 votes
1 answer