This file contains 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
#!/bin/sh | |
# WARNING: REQUIRES /bin/sh | |
# | |
# - must run on /bin/sh on solaris 9 | |
# - must run on /bin/sh on AIX 6.x | |
# | |
# Copyright:: Copyright (c) 2010-2015 Chef Software, Inc. | |
# License:: Apache License, Version 2.0 | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); |
This file contains 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
gfixup() { | |
set -x | |
git add --all | |
git commit --fixup=$(git log --oneline | head -1 | cut -d ' ' -f 1) | |
git rebase --interactive HEAD~2 --autosquash | |
set +x | |
local branch_name=$(git symbolic-ref -q HEAD) | |
branch_name=${branch_name##refs/heads/} | |
branch_name=${branch_name:-HEAD} |
This file contains 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
# Run nginx docker container in background | |
docker run --name nginx --rm -d -p 8080:80 -v ${PWD}:/usr/share/nginx/html:ro nginx | |
# Load a file in curent directory | |
curl http://localhost:8080/index.html | |
# Stop the docker container (the container will be removed / cleaned up) | |
docker stop nginx |
This file contains 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
# Allows copying of job files to local after execution. Example copy command: | |
# | |
# kubectl apply -f ./export-file-job.yaml | |
# POD=$(kubectl get pod --selector=job-name=export-files -o jsonpath='{.items[0].metadata.name}') | |
# kubectl wait pod/$POD --for=condition=ready | |
# until kubectl logs $POD | grep 'Ready for download'; do sleep 2; done | |
# kubectl cp $POD:files.zip ./job-files-$(date +"%Y%m%d%H%M").zip | |
# | |
# Another option would be for the `export-files` container to be a webserver to | |
# serve of the artifact files to be downloaded with `kubectl port-forward ...`. |
This file contains 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
# get instance attrs | |
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) | |
PRIVATE_IP=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4) | |
# get asg name | |
ASG_NAME=$(aws autoscaling describe-auto-scaling-instances --region us-east-1 --instance-ids $INSTANCE_ID --query 'AutoScalingInstances[0].AutoScalingGroupName' --output text) | |
# get tags | |
aws ec2 describe-tags --region us-east-1 --filters "Name=resource-id,Values=${INSTANCE_ID}" |
This file contains 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
def delete_message(message): | |
q_region, q_acct_id, q_name = message['eventSourceARN'].split(':')[3:6] | |
sqs = boto3.client('sqs', region_name=q_region) | |
q_url = f'https://{q_region}.queue.amazonaws.com/{q_acct_id}/{q_name}' | |
sqs.delete_message(QueueUrl=q_url, ReceiptHandle=message['receiptHandle']) |
This file contains 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
# Example usage: | |
# OPERATION_ID="$(aws cloudformation create-stack-instances --stack-set-name MyStackSet \ | |
# --deployment-targets "OrganizationalUnitIds=ou-ab12-abcd1234" \ | |
# --regions us-east-1 \ | |
# --output text)" | |
# stackSetOperationWait MyStackSet "${OPERATION_ID}" | |
function stackSetOperationWait { | |
local cmd="aws cloudformation describe-stack-set-operation --stack-set-name ${1?} --operation-id ${2?}" | |
# print out the operation being performed |
This file contains 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
# Example usage: | |
# | |
# $ getCfnExport MyStack-RoleArn | |
# arn:aws:iam:us-east-1:111111111111:TheExportedRole | |
# | |
function getCfnExport { | |
local EXPORT_VALUE="$(aws cloudformation list-exports --output text --query "Exports[?Name=='${1?}'].Value")" | |
if [ -z "$EXPORT_VALUE" ]; then | |
echo "Could not find CloudFormation export '${1}'" 1>&2 |
This file contains 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 | |
import json | |
region = "us-gov-west-1" | |
all_instance_ids = [ | |
i.id for i in boto3.resource("ec2", region_name=region).instances.all() | |
] | |
ssm_inst_paginator = boto3.client("ssm", region_name=region).get_paginator( |
This file contains 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
# SSM Command document to run a Powershell command on Windows instances and a shell command | |
# on Linux instances. The commands are hard-coded, but could be moved to input parameters. | |
schemaVersion: "2.2" | |
description: Run a PowerShell command on Windows instances and a shell command on Linux instances | |
mainSteps: | |
- precondition: | |
StringEquals: [platformType, Windows] | |
action: "aws:runPowerShellScript" | |
name: runPowerShellScript |