Skip to content

Commit

Permalink
feat: or-1349 delete es indices
Browse files Browse the repository at this point in the history
  • Loading branch information
koenmetsu committed Dec 22, 2023
1 parent 5cee740 commit 1323376
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .aws/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ LABEL registry="association-registry"
COPY .aws/ /app
WORKDIR /app

RUN yum install -y bash
RUN yum install -y bash curl

ENTRYPOINT ["./init.sh"]
28 changes: 28 additions & 0 deletions .aws/init.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ for serviceArn in $SERVICES; do
echo "Downscaled desired count for service $serviceArn"
done

# Clear DynamoDB Locks
DYNAMODB_TABLES=`aws dynamodb list-tables --query TableNames[]`
echo "Found DynamoDB tables: $DYNAMODB_TABLES"
DYNAMODB_TABLES=`aws dynamodb list-tables --query TableNames[] --output text`
Expand All @@ -71,6 +72,33 @@ for tableName in $DYNAMODB_TABLES; do
fi
done

# Clear Elasticsearch Indices
# Elasticsearch endpoint
ES_ENDPOINT="${ES_HOST}"

# Authentication credentials from environment variables
ES_USERNAME="${ES_USERNAME}"
ES_PASSWORD="${ES_PASSWORD}"

# Base64 encode the credentials
AUTH=$(echo -n "$ES_USERNAME:$ES_PASSWORD" | base64)

# Query Elasticsearch for indices starting with 'verenigingsregister-'
INDICES=$(curl -s -X GET "$ES_ENDPOINT/_cat/indices/verenigingsregister-*?h=index" -H "Authorization: Basic $AUTH")

echo "Found ElasticSearch indices: $INDICES"

# Loop through the indices and delete them
for index in $INDICES; do
echo "Deleting index: $index"
RESPONSE=$(curl -s -X DELETE "$ES_ENDPOINT/$index" -H "Authorization: Basic $AUTH")
echo "Response: $RESPONSE"
done

echo "Deletion process completed."

# Reset database

# Restore original desired counts
for service in $SERVICES; do
original_count=${original_counts["$service"]}
Expand Down

0 comments on commit 1323376

Please sign in to comment.