Skip to content

Instantly share code, notes, and snippets.

View embano1's full-sized avatar

Michael Gasch embano1

View GitHub Profile
@embano1
embano1 / client.go
Last active April 11, 2024 13:46
gRPC Graceful Shutdown on Client and Server
package main
import (
"context"
"grpc-tutorial/greeter"
"io"
"log"
"os"
"os/signal"
"sync"
@embano1
embano1 / README.MD
Created September 23, 2019 14:54
Dockerfile for Go modules and built cache efficiency

Also works across git branches if you keep the intermediate build images around, e.g. those <none> images in the docker images output.

FROM golang:1.12 AS builder

# enable Go modules support
ENV GO111MODULE=on

WORKDIR $GOPATH/src/github.com/myrepo/myapp
@embano1
embano1 / README.md
Last active June 23, 2023 14:49
EventBridge CloudEvents Input Transformer

About

Transform EventBridge Events to CloudEvents using Input Transformer, incl. projecting AWS Region and Account ID from the EventBridge event to CloudEvent extended attributes.

Note
You can test whether the transformed CloudEvent is valid using this simple CloudEvent validator utility.

Example Event

@embano1
embano1 / examples.md
Last active May 16, 2023 12:14
kubectl JSON and sort examples

get events sorted by counts and only some fields we're interested in

$ kubectl -n pubsub get ev --sort-by count -o custom-columns='NAME:.metadata.name,KIND:involvedObject.kind,MSG:.message,FIRST:firstTimestamp,COUNT:.count'

using go templating

$ kubectl get events  --sort-by='.metadata.creationTimestamp'  -o 'go-template={{range .items}}{{.involvedObject.name}}{{"\t"}}{{.involvedObject.kind}}{{"\t"}}{{.message}}{{"\t"}}{{.reason}}{{"\t"}}{{.type}}{{"\t"}}{{.firstTimestamp}}{{"\n"}}{{end}}'
@embano1
embano1 / README.MD
Last active February 6, 2023 16:29
Global Endpoints IAM Example

Trust Relationship

Assume a role named EventBridgeGlobalEndpoints which is important for the "iam:PassRole" part.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
@embano1
embano1 / handler.ts
Created October 3, 2022 11:31
CloudEvents TypeScript AWS Lambda SQS Example
import {SQSEvent, SQSHandler} from 'aws-lambda';
import {CloudEvent} from 'cloudevents';
export const handler: SQSHandler = async (events: SQSEvent) => {
events.Records.forEach(e => {
const ce: CloudEvent<string> = new CloudEvent<string>(JSON.parse(e.body));
console.log(ce);
});
};
@embano1
embano1 / README.md
Created September 23, 2022 09:29
Build and run AWS Lambda Containers locally with Go and ko on M1 Mac

download Lambda RUI for M1

mkdir -p ~/.aws-lambda-rie && curl -Lo ~/.aws-lambda-rie/aws-lambda-rie \
https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie-arm64 \
&& chmod +x ~/.aws-lambda-rie/aws-lambda-rie

login

@embano1
embano1 / RESULT.md
Last active April 22, 2022 09:01
go 1.18 assert.Equal benchmark
go test -v -bench=. -gcflags '-l -N' -cpu=1,2,4 -benchmem
goos: darwin
goarch: amd64
pkg: github.com/embano1/assertbench
cpu: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
BenchmarkEqualGeneric
BenchmarkEqualGeneric           462083778                2.392 ns/op           0 B/op          0 allocs/op
BenchmarkEqualGeneric-2         504194739                2.391 ns/op           0 B/op          0 allocs/op
BenchmarkEqualGeneric-4 513227227 2.470 ns/op 0 B/op 0 allocs/op
@embano1
embano1 / README.md
Created April 6, 2022 08:58
Retrieve StorageIOAllocation property of a virtual disk
$ ./govc object.collect -json /vcqaDC/vm/vm-with-disk config.hardware.device \
  | jq '.[0].Val.VirtualDevice[]|select(.Key==2000)|.StorageIOAllocation'
{
  "Limit": -1,
  "Shares": {
    "Shares": 1000,
    "Level": "normal"
  },
 "Reservation": 0
@embano1
embano1 / workflow.yaml
Created March 11, 2022 12:15
Github Actions ko cosign Example
name: image
on:
push:
branches: ['main']
workflow_dispatch:
permissions:
contents: read
packages: write