forked from caktus/aws-web-stacks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.py
143 lines (132 loc) · 4.51 KB
/
search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from awacs.aws import Action, Allow, Policy, Principal, Statement
from troposphere import Equals, GetAtt, Not, Output, Ref
from troposphere.elasticsearch import (
Domain,
EBSOptions,
ElasticsearchClusterConfig
)
from . import USE_EB
from .common import dont_create_value
from .template import template
from .utils import ParameterWithDefaults as Parameter
# TODO: clean up naming for this role so it's the same for all configurations
if USE_EB:
instance_role = "WebServerRole"
else:
instance_role = "ContainerInstanceRole"
es_instance_type = template.add_parameter(
Parameter(
"ElasticsearchInstanceType",
Default=dont_create_value,
Description="Elasticsearch instance type. Note: not all types are supported in all regions; see: "
"http://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/"
"aes-supported-instance-types.html",
Type="String",
AllowedValues=[
dont_create_value,
't2.micro.elasticsearch',
't2.small.elasticsearch',
't2.medium.elasticsearch',
'm3.medium.elasticsearch',
'm3.large.elasticsearch',
'm3.xlarge.elasticsearch',
'm3.2xlarge.elasticsearch',
'm4.large.elasticsearch',
'm4.xlarge.elasticsearch',
'm4.2xlarge.elasticsearch',
'm4.4xlarge.elasticsearch',
'm4.10xlarge.elasticsearch',
'c4.large.elasticsearch',
'c4.xlarge.elasticsearch',
'c4.2xlarge.elasticsearch',
'c4.4xlarge.elasticsearch',
'c4.8xlarge.elasticsearch',
'r3.large.elasticsearch',
'r3.xlarge.elasticsearch',
'r3.2xlarge.elasticsearch',
'r3.4xlarge.elasticsearch',
'r3.8xlarge.elasticsearch',
'r4.large.elasticsearch',
'r4.xlarge.elasticsearch',
'r4.2xlarge.elasticsearch',
'r4.4xlarge.elasticsearch',
'r4.8xlarge.elasticsearch',
'r4.16xlarge.elasticsearch',
'i2.xlarge.elasticsearch',
'i2.2xlarge.elasticsearch',
],
ConstraintDescription="must select a valid Elasticsearch instance type.",
),
group="Elasticsearch",
label="Instance Type",
)
es_version = template.add_parameter(
Parameter(
"ElasticsearchVersion",
Default="2.3",
AllowedValues=[
"1.5",
"2.3",
"5.1",
"5.3",
],
Description="Elasticsearch version. Note: t2.micro.elasticsearch instances support only versions 2.3 and 1.5.",
Type="String",
ConstraintDescription="must select a valid Elasticsearch version.",
),
group="Elasticsearch",
label="Version",
)
es_volume_size = template.add_parameter(
Parameter(
"ElasticsearchVolumeSize",
Default="10",
MinValue="10",
MaxValue="1536",
Description="Elasticsearch EBS volume size, in GB. Note: maximum volume size varies by instance type; see: "
"http://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/aes-limits.html"
"#ebsresource.",
Type="Number",
),
group="Elasticsearch",
label="Storage (GB)",
)
es_condition = "Elasticsearch"
template.add_condition(es_condition, Not(Equals(Ref(es_instance_type), dont_create_value)))
# Create an Elasticsearch domain
es_domain = template.add_resource(
Domain(
"ElasticsearchDomain",
AccessPolicies=Policy(
Statement=[
Statement(
Effect=Allow,
Action=[Action("es", "*")],
Principal=Principal("AWS", [GetAtt(instance_role, "Arn")]),
),
]
),
Condition=es_condition,
EBSOptions=EBSOptions(
EBSEnabled=True,
VolumeSize=Ref(es_volume_size),
),
ElasticsearchClusterConfig=ElasticsearchClusterConfig(
InstanceType=Ref(es_instance_type),
),
ElasticsearchVersion=Ref(es_version),
)
)
# Output Elasticsearch domain endpoint and ARN
template.add_output(Output(
"ElasticsearchDomainEndpoint",
Description="Elasticsearch domain endpoint",
Value=GetAtt(es_domain, "DomainEndpoint"),
Condition=es_condition,
))
template.add_output(Output(
"ElasticsearchDomainArn",
Description="Elasticsearch domain ARN",
Value=GetAtt(es_domain, "DomainArn"),
Condition=es_condition,
))