Solution :
If you have the .aws/config file with the roles then please make sure that your config file is correctly formatted. In my case I forgot to put the role_arn = in front of the arn. The default profile will sit in the .aws/credentials file and it contains the access key id and the secret access key of the iam identity.
The config file contains the following role details:
[profile myrole]
role_arn = arn:aws:iam::123456789012:role/My-Role
source_profile = default
mfa_serial = arn:aws:iam::987654321098:mfa/my-iam-identity
region=ap-southeast-2
If you want you can easily test the access by calling
aws sts get-caller-identity --profile myrole
If you are having the MFA enabled like I have then you will need to enter it when prompted as follows:
Enter MFA code for arn:aws:iam::987654321098:mfa/my-iam-identity:
{
"UserId": "ARABCDEFGHIJKLMNOPQRST:botocore-session-15441234567",
"Account": "123456789012",
"Arn": "arn:aws:sts::123456789012:assumed-role/My-Role/botocore-session-15441234567"
}