AWS Organizations 利用環境で Account Management API を使う際の注意点

この記事は公開されてから半年以上経過しています。情報が古い可能性がありますので、ご注意ください。

GetContactInformation / GetAlternateContact API について

AWS Account Management には GetContactInformation という API があります。
こちらを利用して AWS アカウントに登録された連絡先情報(電話番号・住所など)が取得可能です。
以下のように、Orgazniation 管理アカウントからメンバーアカウントの情報が取得できます。

$ aws account get-contact-information --account-id 111122223333
{
    "ContactInformation": {
        "AddressLine1": "[住所]",
        "City": "[市町村]",
        "CompanyName": "[会社名]",
        "CountryCode": "JP",
        "FullName": "[名前]",
        "PhoneNumber": "[電話番号]",
        "PostalCode": "[郵便番号]",
        "StateOrRegion": "Tokyo"
    }
}

マネジメントコンソールでは以下のように表示される項目です。

また GetAlternateContact という API では「代替の連絡先」を取得することが可能です。
こちらも Orgazniation 管理アカウントからメンバーアカウントの情報が取得できます。

$ aws account get-alternate-contact --alternate-contact-type BILLING --account-id 111122223333
{
    "AlternateContact": {
        "AlternateContactType": "BILLING",
        "EmailAddress": "[メールアドレス]",
        "Name": "[名前]",
        "PhoneNumber": "[電話番号]",
        "Title": "[役職]"
    }
}

マネジメントコンソールでは以下のように表示される項目です。

エラー

これらの API を実行した時、以下のようなエラーが発生しました。

$ aws account get-contact-information --account-id 444455556666

An error occurred (AccessDeniedException) when calling the GetContactInformation operation: User: xxxxxxxx is not authorized to perform: account:GetContactInformation (The management account can only be managed using the standalone context from the management account.)

$ aws account get-alternate-contact --alternate-contact-type BILLING --account-id 444455556666

An error occurred (AccessDeniedException) when calling the GetAlternateContact operation: User: xxxxxxxx is not authorized to perform: account:GetAlternateContact (The management account can only be managed using the standalone context from the management account.)

解決方法

AccountId パラメータを省略すると情報取得できました。

$ aws account get-contact-information
{
    "ContactInformation": {
        "AddressLine1": "[住所]",
        "City": "[市町村]",
        "CompanyName": "[会社名]",
        "CountryCode": "JP",
        "FullName": "[名前]",
        "PhoneNumber": "[電話番号]",
        "PostalCode": "[郵便番号]",
        "StateOrRegion": "Tokyo"
    }
}

$ aws account get-alternate-contact --alternate-contact-type BILLING
{
    "AlternateContact": {
        "AlternateContactType": "BILLING",
        "EmailAddress": "[メールアドレス]",
        "Name": "[名前]",
        "PhoneNumber": "[電話番号]",
        "Title": "[役職]"
    }
}

先ほどのエラーは、Organization の管理アカウントから
管理アカウント(つまり自分自身)の連絡先情報を取得しようとしてエラーになっていました。
Organization 管理アカウントの情報を取得する場合は AccountId パラメータを省略しましょう。

補足

Organization に所属する全AWSアカウントの連絡先情報を取得する、といったプログラムを組む場合などに
遭遇しやすいエラーかなと思います。

GetContactInformation API のリファレンスをよく見ると以下のように記載されており、AccountId を外せばいいことが分かります。
(GetAlternateContact のリファレンスにも同様の記載があります)

The management account can’t specify its own AccountId. It must call the operation in standalone context by not including the AccountId parameter.

同じエラーに遭遇した方の力になれれば幸いです。