

# Using API-Level (s3api) commands in the AWS CLI
<a name="cli-services-s3-apicommands"></a>

API レベルのコマンド (`s3api` コマンドセットに含まれる) は、Amazon Simple Storage Service (Amazon S3) API への直接アクセスを提供し、高レベルの `s3` コマンドでは公開されていない一部の操作を有効にします。これらのコマンドは、サービスの機能性への API レベルのアクセスを提供する他の AWS サービスに相当します。`s3` コマンドの詳細については、「[Using high-level (s3) commands in the AWS CLI](cli-services-s3-commands.md)」を参照してください。

このトピックでは、Amazon S3 API にマッピングする低レベルコマンドの使用方法を示す例を示します。さらに、各 S3 API コマンドの例については、「[AWS CLI バージョン 2 リファレンスガイド](https://docs.aws.amazon.com/cli/latest/reference/s3api/index.html)」の「`s3api`」セクションで参照できます。

**Topics**
+ [前提条件](#cli-services-s3-apicommands-prereqs)
+ [カスタム ACL の適用](#cli-services-s3-apicommands-acls)
+ [ログ記録ポリシーの設定](#cli-services-s3-apicommands-logpol)
+ [リソース](#cli-services-s3-apicommands-resources)

## 前提条件
<a name="cli-services-s3-apicommands-prereqs"></a>

`s3api` コマンドを実行するには、次のことが必要です。
+ AWS CLI をインストールして設定します。詳細については、「[AWS CLI の最新バージョンのインストールまたは更新](getting-started-install.md)」および「」を参照してください。[Authentication and access credentials for the AWS CLI](cli-chap-authentication.md)
+ 使用するプロファイルには、例によって実行される AWS オペレーションに対する許可が必要です。
+ Amazon S3 の以下の用語を解説します。
  + **バケット** - トップレベルの Amazon S3 フォルダ。
  + **プレフィックス** - バケット内の Amazon S3 フォルダ。
  + **オブジェクト** - Amazon S3 バケットでホストされているすべてのアイテム。

## カスタム ACL の適用
<a name="cli-services-s3-apicommands-acls"></a>

高レベルコマンドでは、`--acl` オプションを使用して、事前定義されたアクセスコントロールリスト (ACL) を Amazon S3 オブジェクトに適用できます。ただし、そのコマンドを使用してバケット全体の ACL を設定することはできません。ただし、```[put-bucket-acl](https://docs.aws.amazon.com/cli/latest/reference/s3api/put-bucket-acl.html)` API レベルコマンドを使用することで、これを実行できます。

次の例は、完全なコントロールを 2 人の AWS ユーザー (*user1@example.com* と *user2@example.com*) に付与し、読み取りアクセス許可を everyone に付与する方法を示しています。「everyone」の識別子は、パラメータとして渡す特殊な URI から取得されます。

```
$ aws s3api put-bucket-acl --bucket {{amzn-s3-demo-bucket}} --grant-full-control 'emailaddress="{{user1@example.com}}",emailaddress="{{user2@example.com}}"' --grant-read 'uri="http://acs.amazonaws.com/groups/global/AllUsers"'
```

ACL の作成方法の詳細については、*Amazon シンプルストレージサービス API リファレンス*の「[PUT Bucket acl](https://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUTacl.html)」を参照してください。`s3api` など、CLI の `put-bucket-acl` ACL コマンドは、同様の[引数の略記法](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-shorthand.html)を使用します。

## ログ記録ポリシーの設定
<a name="cli-services-s3-apicommands-logpol"></a>

API コマンド `put-bucket-logging` は、バケットのログ記録ポリシーを設定します。

次の例では、AWS ユーザー *user@example.com* にログファイルに対する完全なコントロールが付与され、すべてのユーザーがログファイルに対する読み取り許可を持っています。`put-bucket-acl` コマンドは、Amazon S3 ログ配信システム (URI で指定された) に、バケットへのログの読み取りと書き込みに必要なアクセス許可を付与するためにも必要です。

```
$ aws s3api put-bucket-acl --bucket {{amzn-s3-demo-bucket}} --grant-read-acp 'URI="http://acs.amazonaws.com/groups/s3/LogDelivery"' --grant-write 'URI="http://acs.amazonaws.com/groups/s3/LogDelivery"'
$ aws s3api put-bucket-logging --bucket {{amzn-s3-demo-bucket}} --bucket-logging-status file://logging.json
```

前のコマンドで `logging.json` ファイルの内容は、次のとおりです。

```
{
  "LoggingEnabled": {
    "TargetBucket": "amzn-s3-demo-bucket",
    "TargetPrefix": "amzn-s3-demo-bucketLogs/",
    "TargetGrants": [
      {
        "Grantee": {
          "Type": "AmazonCustomerByEmail",
          "EmailAddress": "{{user@example.com}}"
        },
        "Permission": "FULL_CONTROL"
      },
      {
        "Grantee": {
          "Type": "Group",
          "URI": "http://acs.amazonaws.com/groups/global/AllUsers"
        },
        "Permission": "READ"
      }
    ]
  }
}
```

## リソース
<a name="cli-services-s3-apicommands-resources"></a>

**AWS CLI リファレンス:**
+ [https://docs.aws.amazon.com/cli/latest/reference/s3api/index.html](https://docs.aws.amazon.com/cli/latest/reference/s3api/index.html)
+ [https://docs.aws.amazon.com/cli/latest/reference/s3api/put-bucket-acl.html](https://docs.aws.amazon.com/cli/latest/reference/s3api/put-bucket-acl.html)
+ [https://docs.aws.amazon.com/cli/latest/reference/s3api/put-bucket-logging.html](https://docs.aws.amazon.com/cli/latest/reference/s3api/put-bucket-logging.html)

**サービスリファレンス:**
+ 「[Amazon S3 ユーザーガイド](https://docs.aws.amazon.com//AmazonS3/latest/userguide/UsingBucket.html)」の「*Amazon S3 バケットの操作*」
+ 「[Amazon S3 ユーザーガイド](https://docs.aws.amazon.com//AmazonS3/latest/userguide/UsingObjects.html)」の「*Amazon S3 オブジェクトの操作*」
+ 「[Amazon S3 ユーザーガイド](https://docs.aws.amazon.com//AmazonS3/latest/userguide/ListingKeysHierarchy.html)」の「*プレフィックスと区切り記号によるキーの階層的なリスト*」
+ 「*Amazon S3 ユーザーガイド*」の「[AWS SDK for .NET (低レベル) を使用した S3 バケットへのマルチパートアップロードの中止](https://docs.aws.amazon.com//AmazonS3/latest/userguide/LLAbortMPUnet.html)」