cloud-aws.asciidoc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. [[cloud-aws]]
  2. === AWS Cloud Plugin
  3. The Amazon Web Service (AWS) Cloud plugin uses the
  4. https://github.com/aws/aws-sdk-java[AWS API] for unicast discovery, and adds
  5. support for using S3 as a repository for
  6. {ref}/modules-snapshots.html[Snapshot/Restore].
  7. [[cloud-aws-install]]
  8. [float]
  9. ==== Installation
  10. This plugin can be installed using the plugin manager:
  11. [source,sh]
  12. ----------------------------------------------------------------
  13. sudo bin/plugin install cloud-aws
  14. ----------------------------------------------------------------
  15. The plugin must be installed on every node in the cluster, and each node must
  16. be restarted after installation.
  17. [[cloud-aws-remove]]
  18. [float]
  19. ==== Removal
  20. The plugin can be removed with the following command:
  21. [source,sh]
  22. ----------------------------------------------------------------
  23. sudo bin/plugin remove cloud-aws
  24. ----------------------------------------------------------------
  25. The node must be stopped before removing the plugin.
  26. [[cloud-aws-usage]]
  27. ==== Getting started with AWS
  28. The plugin will default to using
  29. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html[IAM Role]
  30. credentials for authentication. These can be overridden by, in increasing
  31. order of precedence, system properties `aws.accessKeyId` and `aws.secretKey`,
  32. environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_KEY`, or the
  33. elasticsearch config using `cloud.aws.access_key` and `cloud.aws.secret_key`:
  34. [source,yaml]
  35. ----
  36. cloud:
  37. aws:
  38. access_key: AKVAIQBF2RECL7FJWGJQ
  39. secret_key: vExyMThREXeRMm/b/LRzEB8jWwvzQeXgjqMX+6br
  40. ----
  41. [[cloud-aws-usage-security]]
  42. ===== Transport security
  43. By default this plugin uses HTTPS for all API calls to AWS endpoints. If you wish to configure HTTP you can set
  44. `cloud.aws.protocol` in the elasticsearch config. You can optionally override this setting per individual service
  45. via: `cloud.aws.ec2.protocol` or `cloud.aws.s3.protocol`.
  46. [source,yaml]
  47. ----
  48. cloud:
  49. aws:
  50. protocol: https
  51. s3:
  52. protocol: http
  53. ec2:
  54. protocol: https
  55. ----
  56. In addition, a proxy can be configured with the `proxy_host` and `proxy_port` settings (note that protocol can be
  57. `http` or `https`):
  58. [source,yaml]
  59. ----
  60. cloud:
  61. aws:
  62. protocol: https
  63. proxy_host: proxy1.company.com
  64. proxy_port: 8083
  65. ----
  66. You can also set different proxies for `ec2` and `s3`:
  67. [source,yaml]
  68. ----
  69. cloud:
  70. aws:
  71. s3:
  72. proxy_host: proxy1.company.com
  73. proxy_port: 8083
  74. ec2:
  75. proxy_host: proxy2.company.com
  76. proxy_port: 8083
  77. ----
  78. [[cloud-aws-usage-region]]
  79. ===== Region
  80. The `cloud.aws.region` can be set to a region and will automatically use the relevant settings for both `ec2` and `s3`.
  81. The available values are:
  82. * `us-east` (`us-east-1`)
  83. * `us-west` (`us-west-1`)
  84. * `us-west-1`
  85. * `us-west-2`
  86. * `ap-southeast` (`ap-southeast-1`)
  87. * `ap-southeast-1`
  88. * `ap-southeast-2`
  89. * `ap-northeast` (`ap-northeast-1`)
  90. * `eu-west` (`eu-west-1`)
  91. * `eu-central` (`eu-central-1`)
  92. * `sa-east` (`sa-east-1`)
  93. * `cn-north` (`cn-north-1`)
  94. [[cloud-aws-usage-signer]]
  95. ===== EC2/S3 Signer API
  96. If you are using a compatible EC2 or S3 service, they might be using an older API to sign the requests.
  97. You can set your compatible signer API using `cloud.aws.signer` (or `cloud.aws.ec2.signer` and `cloud.aws.s3.signer`)
  98. with the right signer to use. Defaults to `AWS4SignerType`.
  99. [[cloud-aws-discovery]]
  100. ==== EC2 Discovery
  101. ec2 discovery allows to use the ec2 APIs to perform automatic discovery (similar to multicast in non hostile multicast
  102. environments). Here is a simple sample configuration:
  103. [source,yaml]
  104. ----
  105. discovery:
  106. type: ec2
  107. ----
  108. The ec2 discovery is using the same credentials as the rest of the AWS services provided by this plugin (`repositories`).
  109. See <<cloud-aws-usage>> for details.
  110. The following are a list of settings (prefixed with `discovery.ec2`) that can further control the discovery:
  111. `groups`::
  112. Either a comma separated list or array based list of (security) groups.
  113. Only instances with the provided security groups will be used in the
  114. cluster discovery. (NOTE: You could provide either group NAME or group
  115. ID.)
  116. `host_type`::
  117. The type of host type to use to communicate with other instances. Can be
  118. one of `private_ip`, `public_ip`, `private_dns`, `public_dns`. Defaults to
  119. `private_ip`.
  120. `availability_zones`::
  121. Either a comma separated list or array based list of availability zones.
  122. Only instances within the provided availability zones will be used in the
  123. cluster discovery.
  124. `any_group`::
  125. If set to `false`, will require all security groups to be present for the
  126. instance to be used for the discovery. Defaults to `true`.
  127. `ping_timeout`::
  128. How long to wait for existing EC2 nodes to reply during discovery.
  129. Defaults to `3s`. If no unit like `ms`, `s` or `m` is specified,
  130. milliseconds are used.
  131. [[cloud-aws-discovery-permissions]]
  132. ===== Recommended EC2 Permissions
  133. EC2 discovery requires making a call to the EC2 service. You'll want to setup
  134. an IAM policy to allow this. You can create a custom policy via the IAM
  135. Management Console. It should look similar to this.
  136. [source,js]
  137. ----
  138. {
  139. "Statement": [
  140. {
  141. "Action": [
  142. "ec2:DescribeInstances"
  143. ],
  144. "Effect": "Allow",
  145. "Resource": [
  146. "*"
  147. ]
  148. }
  149. ],
  150. "Version": "2012-10-17"
  151. }
  152. ----
  153. [[cloud-aws-discovery-filtering]]
  154. ===== Filtering by Tags
  155. The ec2 discovery can also filter machines to include in the cluster based on tags (and not just groups). The settings
  156. to use include the `discovery.ec2.tag.` prefix. For example, setting `discovery.ec2.tag.stage` to `dev` will only
  157. filter instances with a tag key set to `stage`, and a value of `dev`. Several tags set will require all of those tags
  158. to be set for the instance to be included.
  159. One practical use for tag filtering is when an ec2 cluster contains many nodes that are not running elasticsearch. In
  160. this case (particularly with high `ping_timeout` values) there is a risk that a new node's discovery phase will end
  161. before it has found the cluster (which will result in it declaring itself master of a new cluster with the same name
  162. - highly undesirable). Tagging elasticsearch ec2 nodes and then filtering by that tag will resolve this issue.
  163. [[cloud-aws-discovery-attributes]]
  164. ===== Automatic Node Attributes
  165. Though not dependent on actually using `ec2` as discovery (but still requires the cloud aws plugin installed), the
  166. plugin can automatically add node attributes relating to ec2 (for example, availability zone, that can be used with
  167. the awareness allocation feature). In order to enable it, set `cloud.node.auto_attributes` to `true` in the settings.
  168. [[cloud-aws-discovery-endpoint]]
  169. ===== Using other EC2 endpoint
  170. If you are using any EC2 api compatible service, you can set the endpoint you want to use by setting
  171. `cloud.aws.ec2.endpoint` to your URL provider.
  172. [[cloud-aws-repository]]
  173. ==== S3 Repository
  174. The S3 repository is using S3 to store snapshots. The S3 repository can be created using the following command:
  175. [source,json]
  176. ----
  177. PUT _snapshot/my_s3_repository
  178. {
  179. "type": "s3",
  180. "settings": {
  181. "bucket": "my_bucket_name",
  182. "region": "us-west"
  183. }
  184. }
  185. ----
  186. // AUTOSENSE
  187. The following settings are supported:
  188. `bucket`::
  189. The name of the bucket to be used for snapshots. (Mandatory)
  190. `region`::
  191. The region where bucket is located. Defaults to US Standard
  192. `endpoint`::
  193. The endpoint to the S3 API. Defaults to AWS's default S3 endpoint. Note
  194. that setting a region overrides the endpoint setting.
  195. `protocol`::
  196. The protocol to use (`http` or `https`). Defaults to value of
  197. `cloud.aws.protocol` or `cloud.aws.s3.protocol`.
  198. `base_path`::
  199. Specifies the path within bucket to repository data. Defaults to
  200. value of `repositories.s3.base_path` or to root directory if not set.
  201. `access_key`::
  202. The access key to use for authentication. Defaults to value of
  203. `cloud.aws.access_key`.
  204. `secret_key`::
  205. The secret key to use for authentication. Defaults to value of
  206. `cloud.aws.secret_key`.
  207. `chunk_size`::
  208. Big files can be broken down into chunks during snapshotting if needed.
  209. The chunk size can be specified in bytes or by using size value notation,
  210. i.e. `1g`, `10m`, `5k`. Defaults to `100m`.
  211. `compress`::
  212. When set to `true` metadata files are stored in compressed format. This
  213. setting doesn't affect index files that are already compressed by default.
  214. Defaults to `false`.
  215. `server_side_encryption`::
  216. When set to `true` files are encrypted on server side using AES256
  217. algorithm. Defaults to `false`.
  218. `buffer_size`::
  219. Minimum threshold below which the chunk is uploaded using a single
  220. request. Beyond this threshold, the S3 repository will use the
  221. http://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html[AWS Multipart Upload API]
  222. to split the chunk into several parts, each of `buffer_size` length, and
  223. to upload each part in its own request. Note that positioning a buffer
  224. size lower than `5mb` is not allowed since it will prevents the use of the
  225. Multipart API and may result in upload errors. Defaults to `5mb`.
  226. `max_retries`::
  227. Number of retries in case of S3 errors. Defaults to `3`.
  228. `read_only`::
  229. Makes repository read-only. coming[2.1.0] Defaults to `false`.
  230. The S3 repositories use the same credentials as the rest of the AWS services
  231. provided by this plugin (`discovery`). See <<cloud-aws-usage>> for details.
  232. Multiple S3 repositories can be created. If the buckets require different
  233. credentials, then define them as part of the repository settings.
  234. [[cloud-aws-repository-permissions]]
  235. ===== Recommended S3 Permissions
  236. In order to restrict the Elasticsearch snapshot process to the minimum required resources, we recommend using Amazon
  237. IAM in conjunction with pre-existing S3 buckets. Here is an example policy which will allow the snapshot access to an
  238. S3 bucket named "snaps.example.com". This may be configured through the AWS IAM console, by creating a Custom Policy,
  239. and using a Policy Document similar to this (changing snaps.example.com to your bucket name).
  240. [source,js]
  241. ----
  242. {
  243. "Statement": [
  244. {
  245. "Action": [
  246. "s3:ListBucket",
  247. "s3:GetBucketLocation",
  248. "s3:ListBucketMultipartUploads",
  249. "s3:ListBucketVersions"
  250. ],
  251. "Effect": "Allow",
  252. "Resource": [
  253. "arn:aws:s3:::snaps.example.com"
  254. ]
  255. },
  256. {
  257. "Action": [
  258. "s3:GetObject",
  259. "s3:PutObject",
  260. "s3:DeleteObject",
  261. "s3:AbortMultipartUpload",
  262. "s3:ListMultipartUploadParts"
  263. ],
  264. "Effect": "Allow",
  265. "Resource": [
  266. "arn:aws:s3:::snaps.example.com/*"
  267. ]
  268. }
  269. ],
  270. "Version": "2012-10-17"
  271. }
  272. ----
  273. You may further restrict the permissions by specifying a prefix within the bucket, in this example, named "foo".
  274. [source,js]
  275. ----
  276. {
  277. "Statement": [
  278. {
  279. "Action": [
  280. "s3:ListBucket",
  281. "s3:GetBucketLocation",
  282. "s3:ListBucketMultipartUploads",
  283. "s3:ListBucketVersions"
  284. ],
  285. "Condition": {
  286. "StringLike": {
  287. "s3:prefix": [
  288. "foo/*"
  289. ]
  290. }
  291. },
  292. "Effect": "Allow",
  293. "Resource": [
  294. "arn:aws:s3:::snaps.example.com"
  295. ]
  296. },
  297. {
  298. "Action": [
  299. "s3:GetObject",
  300. "s3:PutObject",
  301. "s3:DeleteObject",
  302. "s3:AbortMultipartUpload",
  303. "s3:ListMultipartUploadParts"
  304. ],
  305. "Effect": "Allow",
  306. "Resource": [
  307. "arn:aws:s3:::snaps.example.com/foo/*"
  308. ]
  309. }
  310. ],
  311. "Version": "2012-10-17"
  312. }
  313. ----
  314. The bucket needs to exist to register a repository for snapshots. If you did not create the bucket then the repository
  315. registration will fail. If you want elasticsearch to create the bucket instead, you can add the permission to create a
  316. specific bucket like this:
  317. [source,js]
  318. ----
  319. {
  320. "Action": [
  321. "s3:CreateBucket"
  322. ],
  323. "Effect": "Allow",
  324. "Resource": [
  325. "arn:aws:s3:::snaps.example.com"
  326. ]
  327. }
  328. ----
  329. [[cloud-aws-repository-endpoint]]
  330. ===== Using other S3 endpoint
  331. If you are using any S3 api compatible service, you can set a global endpoint by setting `cloud.aws.s3.endpoint`
  332. to your URL provider. Note that this setting will be used for all S3 repositories.
  333. Different `endpoint`, `region` and `protocol` settings can be set on a per-repository basis
  334. See <<cloud-aws-repository>> for details.
  335. [[cloud-aws-testing]]
  336. ==== Testing AWS
  337. Integrations tests in this plugin require working AWS configuration and therefore disabled by default. Three buckets
  338. and two iam users have to be created. The first iam user needs access to two buckets in different regions and the final
  339. bucket is exclusive for the other iam user. To enable tests prepare a config file elasticsearch.yml with the following
  340. content:
  341. [source,yaml]
  342. ----
  343. cloud:
  344. aws:
  345. access_key: AKVAIQBF2RECL7FJWGJQ
  346. secret_key: vExyMThREXeRMm/b/LRzEB8jWwvzQeXgjqMX+6br
  347. repositories:
  348. s3:
  349. bucket: "bucket_name"
  350. region: "us-west-2"
  351. private-bucket:
  352. bucket: <bucket not accessible by default key>
  353. access_key: <access key>
  354. secret_key: <secret key>
  355. remote-bucket:
  356. bucket: <bucket in other region>
  357. region: <region>
  358. external-bucket:
  359. bucket: <bucket>
  360. access_key: <access key>
  361. secret_key: <secret key>
  362. endpoint: <endpoint>
  363. protocol: <protocol>
  364. ----
  365. Replace all occurrences of `access_key`, `secret_key`, `endpoint`, `protocol`, `bucket` and `region` with your settings.
  366. Please, note that the test will delete all snapshot/restore related files in the specified buckets.
  367. To run test:
  368. [source,sh]
  369. ----
  370. mvn -Dtests.aws=true -Dtests.config=/path/to/config/file/elasticsearch.yml clean test
  371. ----