repository-s3.asciidoc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. [[repository-s3]]
  2. === S3 Repository Plugin
  3. The S3 repository plugin adds support for using S3 as a repository for
  4. {ref}/modules-snapshots.html[Snapshot/Restore].
  5. *If you are looking for a hosted solution of Elasticsearch on AWS, please visit http://www.elastic.co/cloud.*
  6. :plugin_name: repository-s3
  7. include::install_remove.asciidoc[]
  8. [[repository-s3-usage]]
  9. ==== Getting started with AWS
  10. The plugin provides a repository type named `s3` which may be used when creating a repository.
  11. The repository defaults to using https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html[ECS IAM Role] or
  12. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html[EC2 IAM Role]
  13. credentials for authentication. The only mandatory setting is the bucket name:
  14. [source,js]
  15. ----
  16. PUT _snapshot/my_s3_repository
  17. {
  18. "type": "s3",
  19. "settings": {
  20. "bucket": "my_bucket"
  21. }
  22. }
  23. ----
  24. // CONSOLE
  25. // TEST[skip:we don't have s3 setup while testing this]
  26. [[repository-s3-client]]
  27. ==== Client Settings
  28. The client that you use to connect to S3 has a number of settings available. The
  29. settings have the form `s3.client.CLIENT_NAME.SETTING_NAME`. The default client
  30. name that is looked up by an `s3` repository is `default`. It can be modified
  31. using the <<repository-s3-repository,repository setting>> `client`. For example:
  32. [source,js]
  33. ----
  34. PUT _snapshot/my_s3_repository
  35. {
  36. "type": "s3",
  37. "settings": {
  38. "bucket": "my_bucket",
  39. "client": "my_alternate_client"
  40. }
  41. }
  42. ----
  43. // CONSOLE
  44. // TEST[skip:we don't have s3 setup while testing this]
  45. Most client settings can be added to the `elasticsearch.yml` configuration file
  46. with the exception of the secure settings, which you add to the {es} keystore.
  47. For more information about creating and updating the {es} keystore, see
  48. {ref}/secure-settings.html[Secure settings].
  49. For example, before you start the node, run these commands to add AWS access key
  50. settings to the keystore:
  51. [source,sh]
  52. ----
  53. bin/elasticsearch-keystore add s3.client.default.access_key
  54. bin/elasticsearch-keystore add s3.client.default.secret_key
  55. ----
  56. *All* client secure settings of this plugin are
  57. {ref}/secure-settings.html#reloadable-secure-settings[reloadable]. After you
  58. reload the settings, the internal `s3` clients, used to transfer the snapshot
  59. contents, will utilize the latest settings from the keystore. Any existing `s3`
  60. repositories, as well as any newly created ones, will pick up the new values
  61. stored in the keystore.
  62. NOTE: In progress snapshot/restore tasks will not be preempted by a *reload*
  63. of the client's secure settings. The task will complete using the client as it
  64. was built when the operation started.
  65. The following list contains the available client settings. Those that must be
  66. stored in the keystore are marked as "secure" and are *reloadable*; the other
  67. settings belong in the `elasticsearch.yml` file.
  68. `access_key` ({ref}/secure-settings.html[Secure])::
  69. An s3 access key. The `secret_key` setting must also be specified.
  70. `secret_key` ({ref}/secure-settings.html[Secure])::
  71. An s3 secret key. The `access_key` setting must also be specified.
  72. `session_token`::
  73. An s3 session token. The `access_key` and `secret_key` settings must also
  74. be specified. (Secure)
  75. `endpoint`::
  76. The s3 service endpoint to connect to. This will be automatically
  77. figured out by the s3 client based on the bucket location, but
  78. can be specified explicitly. See http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region.
  79. `protocol`::
  80. The protocol to use to connect to s3. Valid values are either `http`
  81. or `https`. Defaults to `https`.
  82. `proxy.host`::
  83. The host name of a proxy to connect to s3 through.
  84. `proxy.port`::
  85. The port of a proxy to connect to s3 through.
  86. `proxy.username` ({ref}/secure-settings.html[Secure])::
  87. The username to connect to the `proxy.host` with.
  88. `proxy.password` ({ref}/secure-settings.html[Secure])::
  89. The password to connect to the `proxy.host` with.
  90. `read_timeout`::
  91. The socket timeout for connecting to s3. The value should specify the unit. For example,
  92. a value of `5s` specifies a 5 second timeout. The default value is 50 seconds.
  93. `max_retries`::
  94. The number of retries to use when an s3 request fails. The default value is 3.
  95. `use_throttle_retries`::
  96. Whether retries should be throttled (ie use backoff). Must be `true` or `false`. Defaults to `true`.
  97. [[repository-s3-repository]]
  98. ==== Repository Settings
  99. The `s3` repository type supports a number of settings to customize how data is stored in S3.
  100. These can be specified when creating the repository. For example:
  101. [source,js]
  102. ----
  103. PUT _snapshot/my_s3_repository
  104. {
  105. "type": "s3",
  106. "settings": {
  107. "bucket": "my_bucket_name",
  108. "another_setting": "setting_value"
  109. }
  110. }
  111. ----
  112. // CONSOLE
  113. // TEST[skip:we don't have s3 set up while testing this]
  114. The following settings are supported:
  115. `bucket`::
  116. The name of the bucket to be used for snapshots. (Mandatory)
  117. `client`::
  118. The name of the s3 client to use to connect to S3. Defaults to `default`.
  119. `base_path`::
  120. Specifies the path within bucket to repository data. Defaults to
  121. value of `repositories.s3.base_path` or to root directory if not set.
  122. Previously, the base_path could take a leading `/` (forward slash).
  123. However, this has been deprecated and setting the base_path now should
  124. omit the leading `/`.
  125. `chunk_size`::
  126. Big files can be broken down into chunks during snapshotting if needed.
  127. The chunk size can be specified in bytes or by using size value notation,
  128. i.e. `1gb`, `10mb`, `5kb`. Defaults to `1gb`.
  129. `compress`::
  130. When set to `true` metadata files are stored in compressed format. This
  131. setting doesn't affect index files that are already compressed by default.
  132. Defaults to `false`.
  133. `server_side_encryption`::
  134. When set to `true` files are encrypted on server side using AES256
  135. algorithm. Defaults to `false`.
  136. `buffer_size`::
  137. Minimum threshold below which the chunk is uploaded using a single
  138. request. Beyond this threshold, the S3 repository will use the
  139. http://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html[AWS Multipart Upload API]
  140. to split the chunk into several parts, each of `buffer_size` length, and
  141. to upload each part in its own request. Note that setting a buffer
  142. size lower than `5mb` is not allowed since it will prevent the use of the
  143. Multipart API and may result in upload errors. It is also not possible to
  144. set a buffer size greater than `5gb` as it is the maximum upload size
  145. allowed by S3. Defaults to the minimum between `100mb` and `5%` of the heap size.
  146. `canned_acl`::
  147. The S3 repository supports all http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl[S3 canned ACLs]
  148. : `private`, `public-read`, `public-read-write`, `authenticated-read`, `log-delivery-write`,
  149. `bucket-owner-read`, `bucket-owner-full-control`. Defaults to `private`.
  150. You could specify a canned ACL using the `canned_acl` setting. When the S3 repository
  151. creates buckets and objects, it adds the canned ACL into the buckets and objects.
  152. `storage_class`::
  153. Sets the S3 storage class for objects stored in the snapshot repository.
  154. Values may be `standard`, `reduced_redundancy`, `standard_ia`.
  155. Defaults to `standard`. Changing this setting on an existing repository
  156. only affects the storage class for newly created objects, resulting in a
  157. mixed usage of storage classes. Additionally, S3 Lifecycle Policies can
  158. be used to manage the storage class of existing objects.
  159. Due to the extra complexity with the Glacier class lifecycle, it is not
  160. currently supported by the plugin. For more information about the
  161. different classes, see http://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html[AWS Storage Classes Guide]
  162. [[repository-s3-permissions]]
  163. ===== Recommended S3 Permissions
  164. In order to restrict the Elasticsearch snapshot process to the minimum required resources, we recommend using Amazon
  165. IAM in conjunction with pre-existing S3 buckets. Here is an example policy which will allow the snapshot access to an
  166. S3 bucket named "snaps.example.com". This may be configured through the AWS IAM console, by creating a Custom Policy,
  167. and using a Policy Document similar to this (changing snaps.example.com to your bucket name).
  168. [source,js]
  169. ----
  170. {
  171. "Statement": [
  172. {
  173. "Action": [
  174. "s3:ListBucket",
  175. "s3:GetBucketLocation",
  176. "s3:ListBucketMultipartUploads",
  177. "s3:ListBucketVersions"
  178. ],
  179. "Effect": "Allow",
  180. "Resource": [
  181. "arn:aws:s3:::snaps.example.com"
  182. ]
  183. },
  184. {
  185. "Action": [
  186. "s3:GetObject",
  187. "s3:PutObject",
  188. "s3:DeleteObject",
  189. "s3:AbortMultipartUpload",
  190. "s3:ListMultipartUploadParts"
  191. ],
  192. "Effect": "Allow",
  193. "Resource": [
  194. "arn:aws:s3:::snaps.example.com/*"
  195. ]
  196. }
  197. ],
  198. "Version": "2012-10-17"
  199. }
  200. ----
  201. // NOTCONSOLE
  202. You may further restrict the permissions by specifying a prefix within the bucket, in this example, named "foo".
  203. [source,js]
  204. ----
  205. {
  206. "Statement": [
  207. {
  208. "Action": [
  209. "s3:ListBucket",
  210. "s3:GetBucketLocation",
  211. "s3:ListBucketMultipartUploads",
  212. "s3:ListBucketVersions"
  213. ],
  214. "Condition": {
  215. "StringLike": {
  216. "s3:prefix": [
  217. "foo/*"
  218. ]
  219. }
  220. },
  221. "Effect": "Allow",
  222. "Resource": [
  223. "arn:aws:s3:::snaps.example.com"
  224. ]
  225. },
  226. {
  227. "Action": [
  228. "s3:GetObject",
  229. "s3:PutObject",
  230. "s3:DeleteObject",
  231. "s3:AbortMultipartUpload",
  232. "s3:ListMultipartUploadParts"
  233. ],
  234. "Effect": "Allow",
  235. "Resource": [
  236. "arn:aws:s3:::snaps.example.com/foo/*"
  237. ]
  238. }
  239. ],
  240. "Version": "2012-10-17"
  241. }
  242. ----
  243. // NOTCONSOLE
  244. The bucket needs to exist to register a repository for snapshots. If you did not create the bucket then the repository
  245. registration will fail.
  246. Note: Starting in version 7.0, all bucket operations are using the path style access pattern. In previous versions the decision to use virtual hosted style
  247. or path style access was made by the AWS Java SDK.
  248. [[repository-s3-aws-vpc]]
  249. [float]
  250. ==== AWS VPC Bandwidth Settings
  251. AWS instances resolve S3 endpoints to a public IP. If the Elasticsearch instances reside in a private subnet in an AWS VPC then all traffic to S3 will go through that VPC's NAT instance. If your VPC's NAT instance is a smaller instance size (e.g. a t1.micro) or is handling a high volume of network traffic your bandwidth to S3 may be limited by that NAT instance's networking bandwidth limitations.
  252. Instances residing in a public subnet in an AWS VPC will connect to S3 via the VPC's internet gateway and not be bandwidth limited by the VPC's NAT instance.