Skip to content

Instantly share code, notes, and snippets.

@titan-teej
titan-teej / privileged_users_check.sql
Last active June 3, 2024 19:24
Audits your Snowflake account to show which users have privileged access
USE ROLE ACCOUNTADMIN;
USE WAREHOUSE <warehouse_name>;
WITH privileged_users_check AS PROCEDURE()
RETURNS TABLE()
LANGUAGE PYTHON
RUNTIME_VERSION = '3.9'
PACKAGES = ('snowflake-snowpark-python')
HANDLER = 'main'
EXECUTE AS CALLER
@csereno
csereno / Recover-EC2-CW-Alarm.yaml
Created April 19, 2021 18:25
Cloudformation Templates
# CW Alarm Template
#
# Author: Chris Sereno
# Description: This template creates or adds CW alarms to EC2 Instances and will restart and recover instances.
# There are requirements to instance recovery. See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-recover.html
# This is a personal test template and is NOT a vetted or approved template. Use at your own risk.
#
---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'CloudWatch Alarms to recover EC2 Template'
#-----------------------------------------------------------------------------------------------
#copy emr conf
#-----------------------------------------------------------------------------------------------
emr_ip=10.135.241.137
sudo rm -rf /etc/yum.repos.d/emr-*.repo
sudo rm -rf /var/aws/emr/repoPublicKey.txt
sudo mkdir -p /var/aws/emr/
sudo chmod +r -R /var/aws/
sudo rm -rf /etc/spark/
sudo rm -rf /etc/hadoop/
@pubudusj
pubudusj / terraform_attach_manged_role.tf
Last active January 9, 2023 16:31
Terraform attaching existing managed policy to a new role
### New role creation
### Here assume_role_policy MUST be defined for the trust relationship
resource "aws_iam_role" "codedeploy_service_role" {
name = "CodeDeployServiceRole"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
@csereno
csereno / CloudWatch_Alarms_CLI_Commands
Last active July 30, 2023 19:44
AWS CloudWatch EC2 Alarms
Reference: https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/put-metric-alarm.html
===HIGH CPU===
aws cloudwatch put-metric-alarm --alarm-name "High CPU Util on INSTANCE" --alarm-description "Alarm when CPU exceeds 90 percent" --metric-name CPUUtilization --namespace AWS/EC2 --statistic Average --period 300 --threshold 90 --comparison-operator GreaterThanThreshold --dimensions "Name=InstanceId,Value=INSTANCE" --evaluation-periods 2 --alarm-actions "arn:aws:sns:REGION:ACCOUNT:SNSTOPIC" --unit Percent
===HIGH MEM===
aws cloudwatch put-metric-alarm --alarm-name "High Memory Util on INSTANCE" --alarm-description "Alarm when Memory exceeds 90 percent" --metric-name mem_used_percent --namespace AWS/EC2 --statistic Average --period 300 --threshold 90 --comparison-operator GreaterThanThreshold --dimensions "Name=InstanceId,Value=INSTANCEID" --evaluation-periods 2 --alarm-actions "arn:aws:sns:REGION:ACCOUNT:SNSTOPIC" --unit Percent
===StatusCheckFailed===
aws cloudwatch put-metric-alarm --alarm-name "EC
@csereno
csereno / CloudWatchAgentConfig.json
Created October 1, 2018 20:35
AWS CloudWatch Agent configuration file example for Linux with standard /var/log/messages, secure, and yum logs
{
"agent": {
"metrics_collection_interval": 10,
"logfile": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
},
"metrics": {
"metrics_collected": {
"cpu": {
"resources": [
"*"
function get-instances() {
name=$1
(
echo 'Name,PrivateIPAddress,State,LaunchTime (↓)' &&\
aws ec2 describe-instances --filters "Name=tag:Name,Values=$name" |\
jq -r '.Reservations[].Instances[] |
["\(.Tags | map(select(.Key == "Name").Value)[0])-\(.InstanceId)", .PrivateIpAddress, .State.Name, .LaunchTime] |
@csv' |\
tr -d '"' |\
sort -k 4
@andytumelty
andytumelty / aws query example: show VPC ID, Name and CIDR
Last active March 13, 2024 17:56
AWS CLI List VPC ID, Name and CIDR Block
# display VPC ID, CIDR Block and Name
aws ec2 --output text --query 'Vpcs[*].{VpcId:VpcId,Name:Tags[?Key==`Name`].Value|[0],CidrBlock:CidrBlock}' describe-vpcs