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
aws backup list-backup-jobs \ | |
--by-state RUNNING \ | |
--query 'BackupJobs[].BackupJobId' \ | |
--output text | xargs -t -n1 aws backup stop-backup-job --backup-job-id | echo "All RUNNING state backup jobs stopped." | |
aws backup list-backup-jobs \ | |
--by-state CREATED \ | |
--query 'BackupJobs[].BackupJobId' \ | |
--output text | xargs -t -n1 aws backup stop-backup-job --backup-job-id | echo "All CREATED state backup jobs stopped." |
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
# variables.tf | |
variable "transition_enabled" { | |
default = false | |
description = "Enable transition of S3 objects in a given bucket to Glacier storage class" | |
type = bool | |
} | |
variable "transition_to_glacier" { | |
default = 30 | |
description = "The number of days to wait before transitioning an object to Glacier" |
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
func isWeekday(date time.Time) bool { | |
return date.Weekday() != time.Saturday && date.Weekday() != time.Sunday | |
} | |
func getDayOfWeek(date time.Time) int { | |
return int(date.Weekday()) | |
} | |
func getFirstWeekday(date time.Time) time.Time { |
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
import boto3 | |
from datetime import datetime, timedelta | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
# Get the current month and the last month | |
current_month = datetime.now().strftime("%Y-%m") | |
last_month = (datetime.now() - timedelta(days=30)).strftime("%Y-%m") |
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
# Problem Statement/Use Case: Terraform struggles to manage ECS Task Definitions (think k8s manifests for N containers bundled | |
# together) when the image used by the container(s) changes (importantly and especially via. CI/CD like Actions.) | |
# It will always want to update the task definition after the image change, which means destroying and recreating it. | |
# To avoid this disruption and downtime, this workflow snippet does some wacky stuff with Terraform import and moved blocks | |
# as well as editing the constituent code and making sure the repo is up to date as well as the state with the resource. | |
# Import block is a block of code used to reference an existing resource for generating code for it | |
- name: Create import block | |
run: echo -e 'import { \n to = aws_ecs_task_definition.foo \n id = "${{steps.get-task-def.outputs.TASK_DEF_ARN}}"\n}' > generate_import.tf | |
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
import boto3 | |
from datetime import datetime, timedelta | |
from datadog_lambda.metric import lambda_metric | |
def lambda_handler(event, context): | |
# create iam client | |
iam = boto3.client("iam") | |
# List account aliases through the pagination interface | |
paginator = iam.get_paginator("list_account_aliases") |
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
# A script to, with some user help and knowledge of boto3 (or at least its documentation), | |
# derive Terraform import blocks from bulk AWS resources. This is very bad and funny to me in retrospect but | |
# maybe someone will find it useful or a jumping-off point. | |
# I'd maybe do this in Go with https://github.com/hashicorp/terraform-exec or something if I did it again. | |
import boto3 | |
from botocore.exceptions import ClientError | |
import re | |
import os | |
import sys |