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 7, 2020 in Other DevOps Questions by Lakshminarayanan
• 1,370 points
1,238 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, 2020 by MD
• 95,460 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
• 52,350 points
5,216 views
0 votes
0 answers

How to use version name in Bamboo script

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

Apr 9, 2020 in Other DevOps Questions by Abhishek
• 280 points
833 views
0 votes
1 answer

How to configure and execute Azure Devops classic editor pipeline after commit in Github?

If you're looking for CI/CD triggers, all ...READ MORE

answered Feb 10, 2022 in Other DevOps Questions by Bhavitha
• 1,000 points
1,086 views
0 votes
1 answer
0 votes
1 answer

Please provide a shell script which runs to migrate from SVN to GIT

Hi@shashi, You can run the git-svn command. If ...READ MORE

answered Nov 27, 2020 in Other DevOps Questions by MD
• 95,460 points
959 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP