

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

# AWS Cost and Usage Report 使用 的範例 AWS CLI
<a name="cli_cost-and-usage-report-service_code_examples"></a>

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 來執行動作和實作常見案例 AWS Cost and Usage Report。

*Actions* 是大型程式的程式碼摘錄，必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數，但您可以在其相關情境中查看內容中的動作。

每個範例均包含完整原始碼的連結，您可在連結中找到如何設定和執行內容中程式碼的相關指示。

**Topics**
+ [動作](#actions)

## 動作
<a name="actions"></a>

### `delete-report-definition`
<a name="cost-and-usage-report-service_DeleteReportDefinition_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-report-definition`。

**AWS CLI**  
**刪除 AWS 成本和用量報告**  
此範例會刪除 AWS 成本和用量報告。  
命令：  

```
aws cur --region us-east-1 delete-report-definition --report-name "ExampleReport"
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteReportDefinition](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cur/delete-report-definition.html)。

### `describe-report-definitions`
<a name="cost-and-usage-report-service_DescribeReportDefinitions_cli_topic"></a>

以下程式碼範例顯示如何使用 `describe-report-definitions`。

**AWS CLI**  
**擷取 AWS 成本和用量報告清單**  
此範例說明 帳戶擁有 AWS 的成本和用量報告清單。  
命令：  

```
aws cur --region us-east-1 describe-report-definitions --max-items 5
```
輸出：  

```
  {
"ReportDefinitions": [
  {
      "ReportName": "ExampleReport",
      "Compression": "ZIP",
      "S3Region": "us-east-1",
      "Format": "textORcsv",
      "S3Prefix": "exampleprefix",
      "S3Bucket": "example-s3-bucket",
      "TimeUnit": "DAILY",
      "AdditionalArtifacts": [
          "REDSHIFT",
          "QUICKSIGHT"
      ],
      "AdditionalSchemaElements": [
          "RESOURCES"
      ]
  }
]
  }
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DescribeReportDefinitions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cur/describe-report-definitions.html)。

### `put-report-definition`
<a name="cost-and-usage-report-service_PutReportDefinition_cli_topic"></a>

以下程式碼範例顯示如何使用 `put-report-definition`。

**AWS CLI**  
**建立 AWS 成本和用量報告**  
下列`put-report-definition`範例會建立每日 AWS 成本和用量報告，您可以將其上傳至 Amazon Redshift 或 Amazon QuickSight。  

```
aws cur put-report-definition --report-definition file://report-definition.json
```
`report-definition.json` 的內容：  

```
{
    "ReportName": "ExampleReport",
    "TimeUnit": "DAILY",
    "Format": "textORcsv",
    "Compression": "ZIP",
    "AdditionalSchemaElements": [
        "RESOURCES"
    ],
    "S3Bucket": "example-s3-bucket",
    "S3Prefix": "exampleprefix",
    "S3Region": "us-east-1",
    "AdditionalArtifacts": [
        "REDSHIFT",
        "QUICKSIGHT"
    ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [PutReportDefinition](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cur/put-report-definition.html)。