Pause AWS Resources #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Pause AWS Resources | |
| on: | |
| schedule: | |
| - cron: "0 2 * * 1-5" # Runs every day at 6PM PST, Monday to Friday | |
| workflow_dispatch: | |
| jobs: | |
| pause-resources-dev: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE_ARN }} | |
| role-session-name: gha-pause-resources | |
| aws-region: ca-central-1 | |
| - name: Pause AWS Resources | |
| shell: bash | |
| run: | | |
| aws application-autoscaling register-scalable-target --service-namespace ecs --resource-id service/ecs-cluster-node-api-dev/node-api-dev-service --scalable-dimension ecs:service:DesiredCount --suspended-state DynamicScalingInSuspended=true,DynamicScalingOutSuspended=true --no-cli-pager --output json | |
| aws ecs update-service --cluster ecs-cluster-node-api-dev --service node-api-dev-service --desired-count 0 --no-cli-pager --output json | |
| DB_CLUSTER_STATUS=$(aws rds describe-db-clusters --db-cluster-identifier qsawsc-aurora-cluster-dev --query 'DBClusters[0].Status' --output text) | |
| if [ "$DB_CLUSTER_STATUS" = "available" ]; then | |
| aws rds stop-db-cluster --db-cluster-identifier qsawsc-aurora-cluster-dev --no-cli-pager --output json | |
| else | |
| echo "DB cluster is not in an available state. Current state: $DB_CLUSTER_STATUS" | |
| fi |