Skip to content

Instantly share code, notes, and snippets.

View nicc777's full-sized avatar
🏠
Working from home

Nico Coetzee nicc777

🏠
Working from home
  • Utrecht, Netherlands
View GitHub Profile
@nicc777
nicc777 / aws_http_api_to_python_lambda_template.md
Created August 11, 2022 04:44
AWS Lambda Function Template for AWS HTTP API Gateway Proxy Requests

The function is for a SAM template that looks something like the following:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Example Template for AWS HTTP API to Python Lambda Function

Parameters:
  StageNameParameter:
    Type: String
@nicc777
nicc777 / cloudwatch_log_stream_to_file.md
Last active March 7, 2023 13:21
AWS CLI and CloudWatch - Retrieve a log stream to a local file

Assuming you have LOG_GROUP_NAME and STREAM_NAME as environment variables, you can run the following:

aws logs get-log-events --log-group-name "$LOG_GROUP_NAME" --log-stream-name "$STREAM_NAME" | yq -o=json | jq '.events[] | .timestamp, .message' > stream.log

The log entries with timestamp and message will now be in the file stream.log

Another way to format the output (prevent splitting lines for timestamp and message fields):

@nicc777
nicc777 / aws_boto3_and_lambda_functions.md
Last active September 2, 2022 11:24
Python Code Templates

AWS / Boto3 Functions and Lambda Functions

Module header functions

Prerequisite funtion defined early in a module:

import boto3
import traceback
import os
@nicc777
nicc777 / install_aws_cli_v2_using_pip.md
Created June 18, 2022 08:09
Install AWS CLI Version 2 using pip

Command:

pip3 install git+https://github.com/aws/aws-cli.git@v2
@nicc777
nicc777 / embedding-cognito-js-in-simple-html.md
Created May 30, 2022 05:28
Getting the AWS Cognito JavaScript LIbrary (Steps)

Use Case

These steps demonstrate how to get the JavaScript library for AWS Cognito integration when using simple HTML and JavaScript - no frameworks like ReactJS, or other Node type projects.

Prerequisites

Even though you may not want to use a framework, you still require a relatively new stable version of nodejs

My approach:

@nicc777
nicc777 / install_glusterfs_clinet_on_k3s_nodes.sh
Created May 25, 2022 08:29
Provision GlusterFS Mount Points in K3s Nodes running on Multipass
#!/bin/bash
for node in node1 node2 node3 ;do
multipass exec $node -- sudo DEBIAN_FRONTEND=noninteractive apt update
multipass exec $node -- sudo DEBIAN_FRONTEND=noninteractive apt install -yq software-properties-common
multipass exec $node -- sudo DEBIAN_FRONTEND=noninteractive add-apt-repository -y ppa:gluster/glusterfs-7
multipass exec $node -- sudo DEBIAN_FRONTEND=noninteractive apt update
multipass exec $node -- sudo DEBIAN_FRONTEND=noninteractive apt install -y glusterfs-client
multipass exec $node -- sudo mkdir -p /opt/local-path-provisioner
multipass exec $node -- sudo chmod 777 /opt/local-path-provisioner
@nicc777
nicc777 / localclient-glusterfs-mount.sh
Last active May 7, 2022 13:46
GlusterFS Cluster Using MultiPass
#!/bin/sh
HF=/etc/hosts
MP=/glusterfs-data
echo "Updating /etc/hosts"
IP1=$(multipass info glusterfs1 | grep IPv4 | awk '{print $2}')
IP2=$(multipass info glusterfs2 | grep IPv4 | awk '{print $2}')
sudo sed -i '/glusterfs1/d' $HF
sudo sed -i '/glusterfs2/d' $HF
@nicc777
nicc777 / dns-test.groovy
Last active April 29, 2022 12:34
Groovy: Script to run from Jenkins Script Console to Quickly Test DNS to GitHub
import java.net.InetAddress;
import java.net.UnknownHostException;
void displayStuff(String whichHost, InetAddress inetAddress) {
print("--------------------------" + "\n");
print("Which Host:" + whichHost + "\n");
print("Canonical Host Name:" + inetAddress.getCanonicalHostName() + "\n");
print("Host Name:" + inetAddress.getHostName() + "\n");
print("Host Address:" + inetAddress.getHostAddress() + "\n");
}
@nicc777
nicc777 / gitlab-ce-docker.md
Last active April 26, 2022 08:17
Gitlab Community Edition (Docker) with persistant volumes

Prepare volumes

Also refer to the GitLab Documentation

docker volume create gitlab-data
docker volume create gitlab-logs
docker volume create gitlab-config
@nicc777
nicc777 / connect-k8s.md
Last active April 18, 2022 06:41 — forked from Piotr1215/connect-k8s.md
Keep cluster connections separate

How to keep cluster connections cleanly separated

With time the .kube/config file will contain a mix of dev, test and prod cluster references. It is easy to forget switching off from a prod cluster context and make a mistake and run for example kubectl delete ns crossplane-system.

Direnv based setup

Use the following setup to avoid these kinds of errors and keep clusters separate.

Install direnv