Skip to content

Instantly share code, notes, and snippets.

View gbvanrenswoude's full-sized avatar

Gijs van Renswoude gbvanrenswoude

View GitHub Profile
@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 / 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 / whoof.json
Created October 27, 2021 21:46
whoof.json OAS
{
"openapi": "3.0.1",
"info": {
"title": "fwhoof",
"version": "2021-10-17T18:09:20Z"
},
"servers": [
{
"url": "https://whoof.corp"
}
@gbvanrenswoude
gbvanrenswoude / index.py
Created September 17, 2021 14:51
custom-event-bridge-code-binding
# Lets take a simple event
# and event.json is the jsonschema of it
# {
# "administration": "YOURBACKOFFICECODE",
# "personNumber": 1337
# }
import json
from logging import getLogger, INFO
@gbvanrenswoude
gbvanrenswoude / index.py
Last active September 17, 2021 14:48
eventbridge-lambda-model-premade-AWSEvent
from schema.your_schema_openapiv3 import Event
from schema.your_schema_openapiv3 import AWSEvent
from schema.your_schema_openapiv3 import Marshaller
import json
def lambda_handler(event, context):
"""function
Parameters
----------
@gbvanrenswoude
gbvanrenswoude / proxy-wss-to-request-authorizer.ts
Last active August 30, 2021 17:13
AWS API Gateway v2 Websocket API - Custom Lambda Authorizer for JWT Token
// Proxies https://github.com/ottokruse/aws-apigw-authorizer to function as a Custom Authorizer for AWS API Gatewayv2 Websocket Custom Authorizer when sending JWT tokens.
// Send your JWT token as a querystringparameter 't' in the connection url to your Websocket api
// or set your own querystringparameter name using process.env.webSocketQueryStringParameterName
import { ApiGatewayAuthorizer } from 'aws-apigw-authorizer';
import * as AWSLambda from 'aws-lambda';
const lambdaAuthorizer = new ApiGatewayAuthorizer({ policyBuilder: customPolicyBuilder });
// NOTE type checking seems off in the source, this does not return a AWSLambda.PolicyDocument, but we ignore it
@gbvanrenswoude
gbvanrenswoude / grafana-dashboard-handler.py
Created July 8, 2021 13:18
A grafana dashboard CR handler leveraging requests.
import json
import os
import requests
from requests.structures import CaseInsensitiveDict
headers = {"Accept": "application/json","Content-Type": "application/json" ,"Authorization": "Bearer " + os.environ['grafana_pw']}
# package dashboard with on the fs since usually the string is too long
with open("dashboard.json") as file:
from requests_aws4auth import AWS4Auth
import boto3
import requests
credentials = boto3.Session().get_credentials()
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, 'eu-central-1', 'es', session_token=credentials.token)
r = requests.get(url, auth=awsauth)
# Talk to an AWS IAM protected ElasticSearch cluster
# Since its pretty hard to resort for this kind of stuff to curl (or extentions on it) we use Python
# Also, since its bothersome to check for the correct credentials place (disk, env, metadata endpoint, containerdata endpoint)
# its better to just peel out SigV4Auth from botocore.auth
# pip3 install boto3 requests
import boto3
from botocore.auth import SigV4Auth
from botocore.awsrequest import AWSRequest
import requests, sys
@gbvanrenswoude
gbvanrenswoude / alb-oidc.py
Last active April 8, 2021 13:26
oidc-on-aws-alb with aws cdk (python)
from aws_cdk import (
core,
aws_elasticloadbalancingv2 as elbv2,
aws_secretsmanager as sm
)
[...]
secret_bundle = sm.Secret.from_secret_arn(
self,