-
Notifications
You must be signed in to change notification settings - Fork 13
46 lines (39 loc) · 1.44 KB
/
delete-ecs-task-defs.yml
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
name: Delete ECS task definitions
on:
workflow_dispatch:
schedule:
- cron: "0 5 * * 0" # 5am Sunday UTC
env:
AWS_REGION: ca-central-1
jobs:
delete-ecs-task-definitions:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- env: 'Staging'
secret_prefix: ''
- env: 'Production'
secret_prefix: 'PROD_'
steps:
- name: Checkout
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@8c3f20df09ac63af7b3ae3d7c91f105f857d8497 # v4.0.0
with:
aws-access-key-id: ${{ secrets[format('{0}AWS_ACCESS_KEY_ID', matrix.secret_prefix)] }}
aws-secret-access-key: ${{ secrets[format('{0}AWS_SECRET_ACCESS_KEY', matrix.secret_prefix)] }}
aws-region: ${{ env.AWS_REGION }}
# Retrieves all ACTIVE task definitions except for the 5 most recent
- name: Get ${{ matrix.env }} ECS task definitions
run: |
aws ecs list-task-definitions \
--sort ASC \
--status ACTIVE \
--region ${{ env.AWS_REGION }} \
--no-cli-pager \
| jq -r '(.taskDefinitionArns[:length-6])[]' > task-def-arns.txt
- name: Delete ${{ matrix.env }} ECS task definitions
run: |
./bin/delete-ecs-task-defs.sh task-def-arns.txt