Skip to content

Commit 396509e

Browse files
authored
Update to work with updated AWS requirements (#14)
1 parent e0df139 commit 396509e

File tree

4 files changed

+10
-21
lines changed

4 files changed

+10
-21
lines changed

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,6 @@ Available targets:
8383
lint Lint terraform code
8484
8585
```
86-
## Module: cloudposse/terraform-aws-lambda-elasticsearch-cleanup
87-
88-
This module creates a scheduled Lambda function which will delete old
89-
Elasticsearch indexes using SigV4Auth authentication. The lambda
90-
function can optionally send output to an SNS topic if the topic ARN
91-
is given
92-
9386
## Inputs
9487

9588
| Name | Description | Type | Default | Required |
@@ -101,7 +94,7 @@ is given
10194
| es_domain_arn | The Elasticsearch domain ARN | string | - | yes |
10295
| es_endpoint | The Elasticsearch endpoint for the Lambda function to connect to | string | - | yes |
10396
| es_security_group_id | The Elasticsearch cluster security group ID | string | - | yes |
104-
| index | Index/indices to process. Use a comma-separated list. Specify `all` to match every index except for `.kibana` | string | `all` | no |
97+
| index | Index/indices to process. Use a comma-separated list. Specify `all` to match every index except for `.kibana` or `.kibana_1` | string | `all` | no |
10598
| index_format | Combined with 'index' variable and is used to evaluate the index age | string | `%Y.%m.%d` | no |
10699
| name | Solution name, e.g. 'app' or 'cluster' | string | `app` | no |
107100
| namespace | Namespace, which could be your organization name, e.g. 'eg' or 'cp' | string | - | yes |

docs/terraform.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
## Module: cloudposse/terraform-aws-lambda-elasticsearch-cleanup
2-
3-
This module creates a scheduled Lambda function which will delete old
4-
Elasticsearch indexes using SigV4Auth authentication. The lambda
5-
function can optionally send output to an SNS topic if the topic ARN
6-
is given
7-
81
## Inputs
92

103
| Name | Description | Type | Default | Required |
@@ -16,7 +9,7 @@ is given
169
| es_domain_arn | The Elasticsearch domain ARN | string | - | yes |
1710
| es_endpoint | The Elasticsearch endpoint for the Lambda function to connect to | string | - | yes |
1811
| es_security_group_id | The Elasticsearch cluster security group ID | string | - | yes |
19-
| index | Index/indices to process. Use a comma-separated list. Specify `all` to match every index except for `.kibana` | string | `all` | no |
12+
| index | Index/indices to process. Use a comma-separated list. Specify `all` to match every index except for `.kibana` or `.kibana_1` | string | `all` | no |
2013
| index_format | Combined with 'index' variable and is used to evaluate the index age | string | `%Y.%m.%d` | no |
2114
| name | Solution name, e.g. 'app' or 'cluster' | string | `app` | no |
2215
| namespace | Namespace, which could be your organization name, e.g. 'eg' or 'cp' | string | - | yes |

lambda/es-cleanup.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# -*- coding: utf-8 -*-
33
"""
44
This AWS Lambda function allowed to delete the old Elasticsearch index
5+
6+
THIS FILE IS NOT EXACTLY THE ORIGINAL FILE DISTRIBUTED BY Cloudreach Europe Limited
7+
IT HAS BEEN MODIFIED BY Cloud Posse, LLC
58
"""
69

710
from __future__ import print_function
@@ -14,8 +17,8 @@
1417
from botocore.auth import SigV4Auth
1518
from botocore.awsrequest import AWSRequest
1619
from botocore.credentials import create_credential_resolver
20+
from botocore.httpsession import URLLib3Session
1721
from botocore.session import get_session
18-
from botocore.vendored.requests import Session
1922
import sys
2023
if sys.version_info[0] == 3:
2124
from urllib.request import quote
@@ -117,7 +120,7 @@ def send_to_es(self, path, method="GET", payload={}):
117120

118121
try:
119122
preq = req.prepare()
120-
session = Session()
123+
session = URLLib3Session()
121124
res = session.send(preq)
122125
if res.status_code >= 200 and res.status_code <= 299:
123126
# print("%s %s" % (res.status_code, res.content))
@@ -186,9 +189,9 @@ def lambda_handler(event, context):
186189
earliest_to_keep = datetime.date.today() - datetime.timedelta(
187190
days=int(es.cfg["delete_after"]))
188191
for index in es.get_indices():
189-
if index["index"] == ".kibana":
192+
if index["index"] == ".kibana" or index["index"] == ".kibana_1":
190193
# ignore .kibana index
191-
print("Found .kibana index - ignoring")
194+
print("Found Kibana index: %s - ignoring" % index["index"])
192195
continue
193196

194197
idx_name = '-'.join(word for word in index["index"].split("-")[:-1])

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ variable "sns_arn" {
3939
variable "index" {
4040
type = "string"
4141
default = "all"
42-
description = "Index/indices to process. Use a comma-separated list. Specify `all` to match every index except for `.kibana`"
42+
description = "Index/indices to process. Use a comma-separated list. Specify `all` to match every index except for `.kibana` or `.kibana_1`"
4343
}
4444

4545
variable "delete_after" {

0 commit comments

Comments
 (0)