So, here I came across a very strange scenario,

My server is configured with IAM role with s3 full access. But my code uses a profile ‘aap_connect’ and I don’t want to change anything from code level. I want to use IAM role with same profile but don’t want to use credentials in .aws/credentials file. My current .aws/credentials file look like below,

[aap_connect]
aws_access_key_id=XXXX
aws_secret_access_key=XXXX

To resolve the above situation I have removed the aws_access_key_id and aws_secret_access_key from the credential file just keep the [aap_connect] like below,

[aap_connect]

However, since I mentioned that I don’t want to change anything from the code level, I have to set the AWS_PROFILE environment variable on the server to aap_connect. To do this add the following line to the ~/.bashrc file,

export AWS_PROFILE=aap_connect

Save and close the file after making the changes. Then, open a new terminal window or run the following command to apply the changes to the current terminal session:

source ~/.bashrc

Now the commands will work as it is before with the same profile name, without access key and secrete key but with IAM role.

aws s3 cp test.txt s3://testbucket/ –profile aap_connect

Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *