Skip to content

Instantly share code, notes, and snippets.

View alisade's full-sized avatar

Ali Ardestani alisade

  • Los Angeles, CA
View GitHub Profile
// Enable GuardDuty delegated admin
if (enableGuardDuty) {
const guardDutyPolicy = cr.AwsCustomResourcePolicy.fromStatements([
// from https://docs.aws.amazon.com/guardduty/latest/ug/organizations_permissions.html
new iam.PolicyStatement({
actions: [
'guardduty:EnableOrganizationAdminAccount',
'guardduty:ListOrganizationAdminAccounts',
'guardduty:DisableOrganizationAdminAccount',
],
#!/bin/bash
# Specify the desired volume size in GiB as a command line argument. If not specified, default to 20 GiB.
SIZE=${1:-20}
# Get the ID of the environment host Amazon EC2 instance.
TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 60")
INSTANCEID=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/instance-id 2> /dev/null)
REGION=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/placement/region 2> /dev/null)
#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
set -euo pipefail
# This script is invoked in /etc/cron.d/c9-automatic-shutdown
# which uses the full path to the file: /home/<username>/.c9/stop-if-inactive.sh
# Parse the username from the file path, which can vary based on the Cloud9's OS.
USER=$(echo $0 | cut -d'/' -f3)
CONFIG=$(cat /home/$USER/.c9/autoshutdown-configuration)
@alisade
alisade / multi_part_copy.py
Created November 21, 2022 19:15
merge existing files on s3 without downloading them first using multi part copy
# Using s3 copy with multipart uploads for efficient file merging
# limitation: min part size is 5MB
import boto3
from datetime import datetime
client = boto3.client('s3')
now = datetime.now()
timestamp = now.strftime("%Y%m%d_%H%M%S")
bucket = "bucket-testing-dev"
@alisade
alisade / gist:1da1ae25399e9bfffb558645330a50c9
Last active October 27, 2021 15:22
simple https server
echo -e "HTTP/1.1 200 OK\r\n$(date)\r\n\r\n<h1>hello world from $(hostname) on $(date)</h1>" | sudo ncat -vl --ssl 443
AWSTemplateFormatVersion: '2010-09-09'
Metadata:
License: Apache-2.0
Description: '@Author: Sanjay Garje. AWS CloudFormation Sample Template SageMaker NotebookInstance: This template demonstrates
the creation of a SageMaker NotebookInstance with encryption. You will be billed for the AWS resources used if you create a stack from
this template.'
Parameters:
NotebookInstanceName:
AllowedPattern: '[A-Za-z0-9-]{1,63}'
ConstraintDescription: Maximum of 63 alphanumeric characters. Can include hyphens
@alisade
alisade / gist:42c681998d2e5d7867e80be645b6913f
Created April 1, 2021 15:07
jenkins parallel build agent
// Job == agent-build_pipeline
// build agent for linux/windows
currentBuild.description = env.TAG
def WORKER='worker-large'
def OS = [ 'redhat', 'debian' ]
def ARCH = [ '64' ]
def pipeline_branches = [:]
def JB='./jenkins/build'
def jbuild = { sh "bash ${JB}/build.sh" }
def provision = { sh "bash ${JB}/provision.sh" }
source ~/ssh-agent.sh
sshagent_init
#!/usr/bin/env python3
import boto3
import json
import uuid
import sys
from time import sleep
import backoff
from botocore import exceptions
if len(sys.argv) < 2 :
@alisade
alisade / amazon-eks-nodegroup-role.yaml
Last active November 24, 2019 02:39
instance profile for eks worker nodes
AWSTemplateFormatVersion: "2010-09-09"
Description: Amazon EKS - Node Group Role
Resources:
NodeInstanceRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"