Skip to content

Instantly share code, notes, and snippets.

View thomaspoignant's full-sized avatar

Thomas Poignant thomaspoignant

View GitHub Profile
@thomaspoignant
thomaspoignant / pipeline.yaml
Created April 16, 2021 09:22
Pipeline configuration example
root: handler1_name
steps:
handler1_name:
type: handlerImpl1
next: handler2_name
handler2_name:
type: handlerImpl2
/**
* createApiGatewayForLambda is creating a Rest API Gateway to access to your lambda function
* @param id - CDK id for this lambda
* @param handler - Lambda function to call
* @param description - Description of this endpoint
*/
createApiGatewayForLambda(id: string, handler: lambda.Function, description: string): LambdaRestApi{
return new LambdaRestApi(this, id, {
handler,
description
/**
* buildAndInstallGOLambda build the code and create the lambda
* @param id - CDK id for this lambda
* @param lambdaPath - Location of the code
* @param handler - name of the handler to call for this lambda
*/
buildAndInstallGOLambda(id: string, lambdaPath: string, handler: string): lambda.Function {
const environment = {
CGO_ENABLED: '0',
GOOS: 'linux',
var chiLambda *chiadapter.ChiLambda
// handler is the function called by the lambda.
func handler(ctx context.Context, req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
return chiLambda.ProxyWithContext(ctx, req)
}
// main is called when a new lambda starts, so don't
// expect to have something done for every query here.
func main() {
@thomaspoignant
thomaspoignant / monitor_nested.ts
Last active February 18, 2021 09:59
Use NestedStack to use the type
import * as cdk from '@aws-cdk/core';
import {CfnResource} from "@aws-cdk/core";
export class CdkCustomResourcesStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const monitorType = new CfnResource(this, 'datadog_monitor_id',{
type: 'AWS::CloudFormation::ResourceVersion',
properties:{
@thomaspoignant
thomaspoignant / monitor.ts
Last active February 18, 2021 09:57
Create custom resource with CDK
new CfnResource(this, 'datadog_monitor_id',{
type: 'AWS::CloudFormation::ResourceVersion',
properties:{
'TypeName': 'Datadog::Monitors::Monitor',
'SchemaHandlerPackage':
's3://datadog-cloudformation-resources/datadog-monitors-monitor/datadog' +
'-monitors-monitor-2.1.0.zip'
}
})
@thomaspoignant
thomaspoignant / Makefile
Last active April 5, 2024 08:50
My ultimate Makefile for Golang Projects
GOCMD=go
GOTEST=$(GOCMD) test
GOVET=$(GOCMD) vet
BINARY_NAME=example
VERSION?=0.0.0
SERVICE_PORT?=3000
DOCKER_REGISTRY?= #if set it should finished by /
EXPORT_RESULT?=false # for CI please set EXPORT_RESULT to true
GREEN := $(shell tput -Txterm setaf 2)
var cache map[string]interface{}
func main() {
ticker = time.NewTicker(3 * time.Second)
defer ticker.Stop() // stop the ticker
updaterChan = make(chan struct{})
defer close(updaterChan) // close the channel
// ...
ticker = time.NewTicker(3 * time.Second)
defer ticker.Stop() // stop the ticker
//...
case <- ticker.C:
// update cache
// ...
@thomaspoignant
thomaspoignant / ticker.go
Last active July 17, 2023 23:27
GO periodically refreshing Cache implementation
package main
import (
"fmt"
"sync"
"time"
)
var mutex sync.RWMutex
var cache map[string]interface{}