Change AWS EC2 instance aws_access_key_id & aws_secret_access_key

Solution for Change AWS EC2 instance aws_access_key_id & aws_secret_access_key
is Given Below:

We have an AWS EC2 instance, where someone has removed the USER CREDIANTIALS.
So when we run the .aws/credentials we get a aws_access_key_id & aws_secret_access_key which doesn’t exists anymore.

[email protected]:~$ cat .aws/credentials
[default]
aws_access_key_id = AKIASIY3TRVDD7QZXXXX
aws_secret_access_key = f7rA1eebxzdd61yP4vPTNql09FxgZZam/V5HxxXx

Now I have created another user and add their aws_access_key_id & aws_secret_access_key on the server by

export AWS_ACCESS_KEY_ID=AKIASIY3TRVDCDXXXXXX
export AWS_SECRET_ACCESS_KEY=cgGjUlh5FDPLpUVBBK5Rl8jlWKV6Iv4NrXXXXXX

After that when I run cat .aws/credentials again it still show me the previous user crediantials.

[email protected]:~$ cat .aws/credentials
[default]
aws_access_key_id = AKIASIY3TRVDD7QZXXXX
aws_secret_access_key = f7rA1eebxzdd61yP4vPTNql09FxgZZam/V5HxxXx

Does anyone know how can I change the Crediantials of the Old one with the new user’s credentials?

Go to the .aws/credetials file and use vim or nano to edit the file and replace the older credentials with your new credentials it will work.