Skip to content

Commit 7fc2ea9

Browse files
committed
[add-manifests] add manifests
1 parent 425f280 commit 7fc2ea9

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

.github/workflows/python-app.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Python application
5+
6+
on:
7+
push:
8+
branches: [ master ]
9+
pull_request:
10+
branches: [ master ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Set up Python 3.8
20+
uses: actions/setup-python@v2
21+
with:
22+
python-version: 3.8
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
27+
- name: Lint with pycodestyle
28+
run: |
29+
pycodestyle *.py

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.zip

lambda_function.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os
2+
import boto3
3+
import curator
4+
from requests_aws4auth import AWS4Auth
5+
from elasticsearch import Elasticsearch, RequestsHttpConnection
6+
7+
ES_HOST = os.environ.get('ES_HOST', 'localhost')
8+
ES_REGION = os.environ.get('ES_REGION', 'us-west-1')
9+
ES_INDICES_PREFIX = os.environ.get('ES_INDICES_PREFIX', 'logs')
10+
ES_INDICES_DATA_RETENTION_THRESHOLD_IN_DAYS = os.environ.get('ES_INDICES_DATA_RETENTION_THRESHOLD_IN_DAYS', '90')
11+
ES_INDICES_DATE_FORMAT = os.environ.get('ES_INDICES_DATE_FORMAT', '%Y.%m.%d')
12+
AWS_SERVICE = "es"
13+
14+
15+
def lambda_handler(event, context):
16+
"""
17+
Lambda Handler
18+
"""
19+
20+
# getting credentials
21+
credentials = boto3.Session().get_credentials()
22+
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, ES_REGION, AWS_SERVICE, session_token=credentials.token)
23+
24+
elasticsearch_client_obj = Elasticsearch(hosts=[{'host': ES_HOST, 'port': 443}],
25+
http_auth=awsauth,
26+
use_ssl=True,
27+
verify_certs=True,
28+
connection_class=RequestsHttpConnection
29+
)
30+
31+
index_list = curator.IndexList(elasticsearch_client_obj)
32+
33+
# filter the indices based on the prefix (ES_INDICES_PREFIX).
34+
index_list.filter_by_regex(kind='prefix',
35+
value=ES_INDICES_PREFIX)
36+
37+
if index_list.indices:
38+
# filter the logs indices that are ES_INDICES_DATA_RETENTION_THRESHOLD_IN_DAYS days old
39+
index_list.filter_by_age(source='name',
40+
direction='older',
41+
timestring=ES_INDICES_DATE_FORMAT,
42+
unit='days',
43+
unit_count=int(ES_INDICES_DATA_RETENTION_THRESHOLD_IN_DAYS))
44+
45+
# check if indices exist
46+
if index_list.indices:
47+
curator.DeleteIndices(index_list).do_action()

requirements.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
boto3==1.13.12
2+
botocore==1.16.12
3+
pycodestyle==2.5.0
4+
elasticsearch==7.7.0
5+
requests==2.23.0
6+
requests-aws4auth==0.9
7+
urllib3==1.24.3
8+
elasticsearch-curator==5.8.1

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pycodestyle]
2+
ignore = E402,W504,E124,E126,E122
3+
max-line-length = 150

0 commit comments

Comments
 (0)