2
votes

I have a CloudFormation template in which I would like to output a variable that contains the name of the account that the template was deployed to.

I've found a way to retrieve the Account Id via this Psuedo Parameter:

AWS::AccountId

This is described on the Pseudo Parameters Reference page here:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/pseudo-parameter-reference.html

I'd like to know if there's any way to do the same for the Account Name.

1

1 Answers

1
votes

Not sure what do you mean by "account name". In AWS you only have the following two AWS account identifiers:

  • AWS account ID
  • Canonical user ID

My guess is that you are referring to account alias. If so, there is no direct way of getting it from CFN. But you can design your own custom resource in CFN. The resource would be in the form of a lambda function which would use AWS API ListAccountAliases to list the account aliases and return them to your template for further use.