Serverless deploy can not assume a role on ECS container


I am using AWS CodeBuild for deploying a serverless application in different accounts. The AWS CodeBuild is running on a ECS container instance in the nonprod account and my purpose is to deploy the app in both nonprod and prod accounts. So I need to switch to the prod account using a cross account role on the ECS instance. I have the cross acount role in the ~/.aws/credentials:
role_arn = arn:aws:iam::43764584623:role/cross_account_role
region = us-east-1
credential_source = EcsContainer

When I run “aws s3 ls --profile prod_profile” I am able to access the prod account. But the “serverless deploy --s prod” command fails with this error:
“Profile prod_profile does not exist”

Is this a bug or I missing something?