I didn't find anything on AWS or boto3 docs that allows for that, but I was able to execute as a different user using the runuser command. In theory, you could do the same thing with a combination of sudo and su commands, but this one is pretty simpler.
For that, you can do as follows:
runuser -l userNameHere -c '/path/to/command arg1 arg2'
The first thing to point out, is that you should already be writing IP tables rules to a file, and restoring them from that file at start up - otherwise you will lose all of the rules when the server reboots.
The standard commands to do this on Debian are:
sudo iptables-save > /etc/iptables.up.rules
sudo iptables-restore < /etc/iptables.up.rules
If you want to modify the configuration and rules, so you must save the current configuration to a file.
So step one is to save the rules configuration by typing the following commands:
$ sudo iptables-save > /root/my-iptables.rules
To restore it just use the command iptables-restore:
$ sudo iptables-restore < /root/my-iptables.rules
⚠️ When you ...