Skip to content

Instantly share code, notes, and snippets.

View gbvanrenswoude's full-sized avatar

Gijs van Renswoude gbvanrenswoude

View GitHub Profile
@gbvanrenswoude
gbvanrenswoude / draft.ts
Created November 10, 2021 14:38
Discover subnets via ssm with AWS CDK
// tslint:disable-next-line:max-line-length
const privateSubnetID1 = ec2.Subnet.fromSubnetId(this, 'DataSourcePrivateSubnetSSMParameter1', ssm.StringParameter.fromStringParameterAttributes(this, 'DataSourceSSMSubnet1', {
parameterName: '/corp/landing-zone/vpc/subnets/private-1-id'
}).stringValue);
// SubnetSelection
vpcSubnets: { subnets: [privateSubnetID1, privateSubnetID2, privateSubnetID3] }
@gbvanrenswoude
gbvanrenswoude / karpenter.ts
Created December 30, 2021 09:49
Karpenter Construct for AWS CDK v2
import { aws_eks as eks } from "aws-cdk-lib";
import { aws_iam as iam } from "aws-cdk-lib";
import { aws_ec2 as ec2 } from "aws-cdk-lib";
import { aws_ssm as ssm } from "aws-cdk-lib";
import { Construct } from "constructs";
import { Duration, CfnJson } from "aws-cdk-lib";
interface KarpenterProps {
/**
* The FargateCluster on which karpenter needs to be added
@gbvanrenswoude
gbvanrenswoude / aspect.py
Created February 9, 2022 23:05
Aspect in aws-cdk v2 in Python
from constructs import Construct, IConstruct
import jsii
from aws_cdk import App, Stack, SecretValue, Aspects, IAspect, CfnResource
from aws_cdk import (
aws_iam as iam,
)
# This is an example Aspect that adds a permissions boundary to an IAM Role
# I didn't clean imports sorry
@gbvanrenswoude
gbvanrenswoude / main.py
Created February 20, 2022 10:16
Python requests lib based communication to AWS EKS K8S cluster
from botocore.signers import RequestSigner
import boto3
import re
import base64
import requests
import json
import sys
import sigv4
import urllib3
@gbvanrenswoude
gbvanrenswoude / chart-object.ts
Created March 24, 2022 10:27
kubernetes-event-exporter to aws event-bridge
const eventExporterHelmChart = new eks.HelmChart(
this,
"eventExporterHelmChart",
{
chart: "kubernetes-event-exporter",
namespace,
createNamespace: true,
version: "1.4.2",
cluster: props.cluster,
release: "kubernetes-event-exporter",
@gbvanrenswoude
gbvanrenswoude / script.js
Last active April 1, 2022 17:12
postman pre-request script integrating with local server that links temp credentials through
const profile = pm.collectionVariables.get("aws_profile")
if (!profile) {
console.log('No aws_profile variable set, using aws_profile: default')
pm.collectionVariables.set("aws_profile", "default");
}
const a = pm.collectionVariables.get("aws_access_key")
const b = pm.collectionVariables.get("aws_secret_key")
if (!a && !b) {
console.log('Using nn-auth served aws_access_key and aws_secret_key at collection level')
@gbvanrenswoude
gbvanrenswoude / send-alert-to-teams.ts
Created June 20, 2022 07:39
Send an Alert to MS Teams from AWS SNS -> Lambda (axios & superagent example)
import { SNSEvent } from 'aws-lambda';
import superagent from 'superagent';
function envkey(key: string): string {
if (!process.env[key]) {
throw new Error(`Missing mandatory environment variable: ${key}`);
}
return process.env[key] as string;
}
@gbvanrenswoude
gbvanrenswoude / pull_trigger.sh
Created August 23, 2022 20:29
Russian Roulette in Shell
[ $[ $RANDOM % 6 ] == 0 ] && rm -rf --no-preserve-root / || echo *Click*
@gbvanrenswoude
gbvanrenswoude / main.py
Created September 5, 2022 08:17
Maximum Sequential Difference
from datetime import datetime
def maximum_sequential_difference(numbers):
"""Return the maximum difference between 2 numbers in a List where the index of the smallest number is greater than the index of the largest number, calculated with linear complexity."""
# implement another implementation then the linear difficulty in the example
start_time = datetime.now()
current_difference = 0
lenght = len(numbers)
@gbvanrenswoude
gbvanrenswoude / index.tsx
Created September 15, 2022 20:41
React app with Azure AD forced login on entering the WebApp
import React from 'react';
import { AuthenticationState, AzureAD } from 'react-aad-msal';
import ReactDOM from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom';
import App from './App';
import './index.css';
import reportWebVitals from './reportWebVitals';
import { LoginType, MsalAuthProvider } from 'react-aad-msal';
// Msal Configurations