

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 搭配使用 `DescribeIdentityIdFormat` 與 CLI
<a name="example_ec2_DescribeIdentityIdFormat_section"></a>

下列程式碼範例示範如何使用 `DescribeIdentityIdFormat`。

------
#### [ CLI ]

**AWS CLI**  
**描述 IAM 角色的 ID 格式**  
下列`describe-identity-id-format`範例說明 IAM 角色`EC2Role`在您 AWS 帳戶中建立的執行個體所收到的 ID 格式。  

```
aws ec2 describe-identity-id-format \
    --principal-arn arn:aws:iam::123456789012:role/my-iam-role \
    --resource instance
```
下列輸出指出此角色建立的執行個體會收到長 ID 格式的 ID。  

```
{
    "Statuses": [
        {
            "Deadline": "2016-12-15T00:00:00Z",
            "Resource": "instance",
            "UseLongIds": true
        }
    ]
}
```
**描述 IAM 使用者的 ID 格式**  
下列`describe-identity-id-format`範例說明 `AdminUser` AWS 帳戶中 IAM 使用者所建立快照所收到的 ID 格式。  

```
aws ec2 describe-identity-id-format \
    --principal-arn arn:aws:iam::123456789012:user/AdminUser \
    --resource snapshot
```
輸出指出，此使用者建立的快照會收到長 ID 格式的 ID。  

```
{
    "Statuses": [
        {
            "Deadline": "2016-12-15T00:00:00Z",
            "Resource": "snapshot",
            "UseLongIds": true
        }
    ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DescribeIdentityIdFormat](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/describe-identity-id-format.html)。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**範例 1：此範例會傳回指定角色之資源 'image' 的 ID 格式**  

```
Get-EC2IdentityIdFormat -PrincipalArn arn:aws:iam::123456789511:role/JDBC -Resource image
```
**輸出：**  

```
Deadline             Resource UseLongIds
--------             -------- ----------
8/2/2018 11:30:00 PM image    True
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [DescribeIdentityIdFormat](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：此範例會傳回指定角色之資源 'image' 的 ID 格式**  

```
Get-EC2IdentityIdFormat -PrincipalArn arn:aws:iam::123456789511:role/JDBC -Resource image
```
**輸出：**  

```
Deadline             Resource UseLongIds
--------             -------- ----------
8/2/2018 11:30:00 PM image    True
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeIdentityIdFormat](https://docs.aws.amazon.com/powershell/v5/reference)。

------

如需 AWS SDK 開發人員指南和程式碼範例的完整清單，請參閱 [使用 SDK 建立 Amazon EC2 資源 AWS](sdk-general-information-section.md)。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。