

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Amazon SES API を使用した使用統計のモニタリング
<a name="monitor-sending-activity-api"></a>

Amazon SES API は、 `GetSendStatistics` オペレーションを使用してサービスの使用に関する情報を返します。送信統計を定期的にチェックし、必要に応じて調整を行うようお勧めします。

`GetSendStatistics` オペレーションを呼び出すと、過去 2 週間の送信アクティビティを示すデータポイントのリストが返されます。このリストの各データポイントは、15 分間のアクティビティを示し、その期間に関する以下の情報が含まれています:
+ ハードバウンス数
+ 苦情数
+ 配信試行回数 (送信した E メールの数に相当します)
+ 送信試行の拒否数
+ 分析期間のタイムスタンプ

`GetSendStatistics` オペレーションの詳細については、[Amazon Simple Email Service API リファレンス](https://docs.aws.amazon.com/ses/latest/APIReference/GetSendStatistics.html)を参照してください。

このセクションでは、以下のトピックについて説明します。
+ [を使用して `GetSendStatistics` API オペレーションを呼び出す AWS CLI](#monitor-sending-activity-api-cli)
+ [プログラムを使用した `GetSendStatistics` オペレーションの呼び出し](#monitor-sending-activity-api-sdk)

## を使用して `GetSendStatistics` API オペレーションを呼び出す AWS CLI
<a name="monitor-sending-activity-api-cli"></a>

`GetSendStatistics` API オペレーションを最も簡単に呼び出す方法は [AWS Command Line Interface](https://aws.amazon.com/cli) (AWS CLI) を使用することです。

**を使用して `GetSendStatistics` API オペレーションを呼び出すには AWS CLI**

1.  AWS CLIをインストールします (まだの場合)。詳細については、 *AWS Command Line Interface ユーザーガイド*[の「 のインストール AWS Command Line Interface](https://docs.aws.amazon.com/cli/latest/userguide/installing.html)」を参照してください。

1. まだ設定していない場合は、認証情報 AWS を使用する AWS CLI ように を設定します。詳細については、 *AWS Command Line Interface ユーザーガイド*[の「 の設定 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html)」を参照してください。

1. コマンドラインから、以下のコマンドを実行します。

   ```
   aws ses get-send-statistics
   ```

    AWS CLI が適切に設定されている場合、JSON 形式の送信統計のリストが表示されます。JSON オブジェクトごとに 15 分間の集約された送信統計が含まれています。

## プログラムを使用した `GetSendStatistics` オペレーションの呼び出し
<a name="monitor-sending-activity-api-sdk"></a>

 AWS SDKs を使用して `GetSendStatistics`オペレーションを呼び出すこともできます。このセクションでは、Go、PHP、Python、Ruby 用の AWS SDKs のコード例を示します。以下のいずれかのリンクを選択すると、その言語でコード例が表示されます。
+ [AWS SDK for Goのコード例](#code-example-getsendstatistics-golang)
+ [AWS SDK for PHPのコード例](#code-example-getsendstatistics-php)
+ [AWS SDK for Python (Boto)のコード例](#code-example-getsendstatistics-python)
+ [AWS SDK for Rubyのコード例](#code-example-getsendstatistics-ruby)

**注記**  
これらのコード例は、 AWS アクセスキー ID、 AWS シークレットアクセスキー、および任意の AWS リージョンを含む AWS 共有認証情報ファイルを作成していることを前提としています。詳細については、「[共有認証情報ファイルと設定ファイル](https://docs.aws.amazon.com/credref/latest/refdocs/creds-config-files.html)」を参照してください。

### `GetSendStatistics` を使用した の呼び出し AWS SDK for Go
<a name="code-example-getsendstatistics-golang"></a>

```
 1. package main
 2.     
 3. import (
 4.     "fmt"
 5.     
 6.     //go get github.com/aws/aws-sdk-go/...
 7.     "github.com/aws/aws-sdk-go/aws"
 8.     "github.com/aws/aws-sdk-go/aws/session"
 9.     "github.com/aws/aws-sdk-go/service/ses"
10.     "github.com/aws/aws-sdk-go/aws/awserr"
11. )
12.     
13. const (
14.     // Replace us-west-2 with the AWS Region you're using for Amazon SES.
15.     AwsRegion = "{{us-west-2}}"
16. )
17.     
18. func main() {
19.     
20.     // Create a new session and specify an AWS Region.
21.     sess, err := session.NewSession(&aws.Config{
22.         Region:aws.String(AwsRegion)},
23.     )
24.     
25.     // Create an SES client in the session.
26.     svc := ses.New(sess)
27.     input := &ses.GetSendStatisticsInput{}
28.     
29.     result, err := svc.GetSendStatistics(input)
30.     
31.     // Display error messages if they occur.
32.     if err != nil {
33.         if aerr, ok := err.(awserr.Error); ok {
34.             switch aerr.Code() {
35.             default:
36.                 fmt.Println(aerr.Error())
37.             }
38.         } else {
39.             // Print the error, cast err to awserr.Error to get the Code and
40.             // Message from an error.
41.             fmt.Println(err.Error())
42.         }
43.         return
44.     }
45.     
46.     fmt.Println(result)
47. }
```

### `GetSendStatistics` を使用した の呼び出し AWS SDK for PHP
<a name="code-example-getsendstatistics-php"></a>

```
 1. <?php
 2. 
 3. // Replace path_to_sdk_inclusion with the path to the SDK as described in 
 4. // http://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/basic-usage.html
 5. define('REQUIRED_FILE','{{path_to_sdk_inclusion}}');
 6.                                                   
 7. // Replace us-west-2 with the AWS Region you're using for Amazon SES.
 8. define('REGION','{{us-west-2}}'); 
 9. 
10. require REQUIRED_FILE;
11. 
12. use Aws\Ses\SesClient;
13. 
14. $client = SesClient::factory(array(
15.     'version'=> 'latest',     
16.     'region' => REGION
17. ));
18. 
19. try {
20.      $result = $client->getSendStatistics([]);
21. 	 echo($result);
22. } catch (Exception $e) {
23.      echo($e->getMessage()."\n");
24. }
25. 
26. ?>
```

### `GetSendStatistics` を使用した の呼び出し AWS SDK for Python (Boto)
<a name="code-example-getsendstatistics-python"></a>

```
 1. import boto3 #pip install boto3
 2. import json
 3. from botocore.exceptions import ClientError
 4. 
 5. client = boto3.client('ses')
 6. 
 7. try:
 8.     response = client.get_send_statistics(
 9. )
10. except ClientError as e:
11.     print(e.response['Error']['Message'])
12. else:
13.     print(json.dumps(response, indent=4, sort_keys=True, default=str))
```

### `GetSendStatistics` を使用して を呼び出す AWS SDK for Ruby
<a name="code-example-getsendstatistics-ruby"></a>

```
 1. require 'aws-sdk' # gem install aws-sdk
 2. require 'json'
 3. 
 4. # Replace us-west-2 with the AWS Region you're using for Amazon SES.
 5. awsregion = "{{us-west-2}}"
 6. 
 7. # Create a new SES resource and specify a region
 8. ses = Aws::SES::Client.new(region: awsregion)
 9. 
10. begin
11. 
12.   resp = ses.get_send_statistics({
13.   })
14.   puts JSON.pretty_generate(resp.to_h)
15. 
16. # If something goes wrong, display an error message.
17. rescue Aws::SES::Errors::ServiceError => error
18.   puts error
19. 
20. end
```