CLI get aws account id


I’ve managed to hack together this piped bash line to receive accountId. Is there some easier way?

serverless info | grep https | sed -E 's/(.*)https:\/\/(.*)/\2/' | cut -d '.' -f 1 | head -n 1


If what you want is to retrieve your AWS account ID to use in your serverless.yml configuration file, I would recommend you to have a look at the serverless-pseudo-parameters plugin.


If you are just looking to retrieve the ID from the command line, then you can use the AWS CLI and run aws sts get-caller-identity --output text --query 'Account'.

Hope it helps! :slightly_smiling_face: