I can successfully upload a file to my S3 bucket using the AWS cli version 1 with my normal linux user. However, I'm having trouble doing the same with Apache2's www-data.
I have a personal project where I have a web form and after submission, I use shell_exec to run some shell commands. I've tried the following command but it does not seem to work and I'm not getting any errors so debugging is a bit hard:
shell_exec('/home/pi/./local/bin/aws s3 cp /path/to/test.txt s3://s3-bucket-name/');
If it makes any difference, I'm doing this on a Raspberry Pi. I'm suspecting it has something to do with the fact that AWS CLI has been installed under the normal user I use and www-data cannot access it.
Edit: One solution I found was to use allow www-data to run commands with another user without prompting for password. So this worked then:
shell_exec('sudo -u pi /home/pi/.local/bin/aws s3 cp /path/to/test.txt s3://s3-bucket-name/');