Skip to content

Instantly share code, notes, and snippets.

@dfetterman
dfetterman / AssumeRole.py
Last active May 2, 2022 15:00
Python Assume Role Example
import boto3
awsaccntid = '123456789123'
targetrole = 'LISTCERTSSTSROLE'
## GET CREDENTIALS
def fn_assume_role(awsaccntid, targetrole):
client = boto3.client('sts')
response = client.assume_role(
RoleArn="arn:aws:iam::" + awsaccntid + ":role/" + targetrole,
@dfetterman
dfetterman / gist:fcd8724e3353566b9105fc68b1142d8c
Created September 13, 2019 16:23
guarddutysignup - Example Serverless Service Information
Service Information
service: guarddutysignup
stage: dev
region: us-east-1
stack: guarddutysignup-dev
resources: 36
api keys:
mykey6: OGyJrKhQHUHNOWAYNOTSHARINGITdEpUc
endpoints:
functions:
@dfetterman
dfetterman / serverless.yml
Last active September 13, 2019 16:10
guarddutysignup example serverless.yml
service: guarddutysignup
custom:
stage: ${opt:stage, self:provider.stage}
memberRoleName: CrossAccountManageGuardDutyRole #The name of the role that will be assumed in member accounts
provider:
name: aws
runtime: python3.6
stage: dev #default stage
@dfetterman
dfetterman / mydata.json
Created June 11, 2019 15:27
Parse s3 json object
[
{
"clientName": "BobSmith",
"clientID": "22oi5qjafaflklkjklajlf",
"postconf": "CanvasCatalog",
"group": "MRH3"
},
{
"clientName": "ToddHarris",
"clientID": "i5qj3klq23rhljkna.nmaf",
@dfetterman
dfetterman / fizzbuzz.py
Created June 11, 2019 12:52
Dane Fetterman's version of FizzBuzz
for x in range(1, 101):
if (x % 5 == 0) and (x % 3 == 0):
print('FizzBuzz')
elif x % 5 == 0: #means x is exactly divisible by 5, therefor it is a multiple of 5
print('Buzz')
elif x % 3 == 0:
print('Fizz')
else:
print(x)
@dfetterman
dfetterman / gist:6d29da0e95f7009d0eae84f874345e09
Created June 10, 2019 18:11
Ansible Example vmware_guest provision without network
- name: "Ensure that virtual machine exists in VMC SDDC"
vmware_guest:
datacenter: "SDDC-Datacenter"
hostname: "{{ vsphere_server }}"
username: "{{ vsphere_user }}"
password: "{{ vsphere_password }}"
validate_certs: no
folder: "/SDDC-Datacenter/vm/Workloads"
name: "ansible-test-rhel-Demo1"
annotation: "This is a test VM created by Ansible"
@dfetterman
dfetterman / gist:ac02e3ccc80aa771d8c428e91ffe51f0
Created June 10, 2019 17:38
Ansible Example vmware_guest provision w/ network
- name: "Ensure that virtual machine exists in VMC SDDC"
vmware_guest:
datacenter: "SDDC-Datacenter"
hostname: "{{ vsphere_server }}"
username: "{{ vsphere_user }}"
password: "{{ vsphere_password }}"
validate_certs: no
folder: "/SDDC-Datacenter/vm/Workloads"
name: "ansible-test-rhel-Demo1"
annotation: "This is a test VM created by Ansible"
@dfetterman
dfetterman / lambda_function-ECS-cloudwatch-slack.py
Last active April 6, 2024 14:40
Lambda function that takes ECS Cloudwatch events and sends a notification to Slack
# Written by Dane Fetterman on 12/1/2016
# https://aws.amazon.com/blogs/compute/monitor-cluster-state-with-amazon-ecs-event-stream/
# Where they use a cloud watch event from ECS to notify a SNS topic. We're
# sending a notification directly to slack instead
import requests
import json
from boto3 import session, client
#!/bin/bash
# myapp daemon
# chkconfig: 345 20 80
# description: myapp daemon
# processname: myapp
DAEMON_PATH="/usr/local/src/logstash/bin"
DAEMON=logstash
DAEMONOPTS="-f /etc/logstash/logstash.conf"
{
"title": "Logstash HTTP Statistics",
"services": {
"query": {
"idQueue": [
1,
2,
3,
4,
5,