Skip to content

Instantly share code, notes, and snippets.

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

Chris Bailey chris

🏠
Working from home
View GitHub Profile
@chris
chris / cognito-paginator.go
Last active April 15, 2024 22:10
Basic AWS API Pagination example (with Cognito)
import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider"
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider/types"
)
// create the AWS client - uses environment/profile for values
cognitoidentityprovider.NewFromConfig(config.LoadDefaultConfig(context.Background()))
@chris
chris / s3-cloudfront-route53.yml
Last active February 17, 2024 21:33
S3 CloudFront Custom Domain CloudFormation example
#
# S3 bucket for a web files, with CloudFront and custom domain.
#
# The bucket is setup to be private, only accessible via CloudFront.
# This uses a CloudFront OAI to provide access to the bucket, and also restricts
# access to be SSL/HTTPS only.
# The SSL cert was created manually, as it has to be created in us-east-1 for
# use with CloudFront, and there is no way to specify a region in CloudFormation
# when creating a cert.
# Finally it does Route53 DNS setup for the subdomain pointed at/for use with
@chris
chris / topfuel_wheel_comparison.csv
Last active April 2, 2023 08:00
Comparison of weight and cost of change in wheels on my Top Fuel
Item Weight Cost
Bontrager Line Elite 30 1890g $1000
CushCore Pro 29 530g $150
Bontrager XR4 2.4 tire 800g $70
Bontrager XR3 2.4 tire 755g $70
TOTAL 3975g $1290 - $0.32/gram
---- ---- ----
Reserve 30 SL w/ I9 hubs 1723g $1900 ($1615)
Tubolight HD 180g $96
Kenda Booster SCT 2.4 tire 690g $75
@chris
chris / ddbstreamprocessor.go
Last active January 12, 2023 02:34
DynamoDB streams lambda trigger handler in Go
package main
import (
"context"
"log"
"os"
"strings"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
@chris
chris / tiled_raster_import.sh
Created January 10, 2023 20:20
Script to import large raster data set in chunks via VRT files.
#!/bin/bash
#
# Script to produce tiled raster import of a large data source, so that we can
# import in chunks, and be able to handle failures. This takes the lat/long
# mins and maxes for a rectangular area, and a VRT tile size and produces VRTs
# for each tile. It also outputs a shell script to import those VRTs along with
# outputting the last "rid" (raster ID in DB) after completing a tile, so that
# if it fails, we know the items to delete (so we can restart the failed tile,
# and not have duplicate records from what was partially imported).
#
@chris
chris / myauthorizer.go
Created June 4, 2021 19:23
Example of an API Gateway Lambda authorizer
package main
import (
"context"
"errors"
"regexp"
"strings"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
@chris
chris / cognito.yml
Created May 21, 2021 17:31
Cognito user pool setup for Serverless (as CloudFormation resource)
#
# Cognito user pool/auth setup
#
Resources:
MyAppUserPool:
Type: AWS::Cognito::UserPool
Properties:
UserPoolName: myapp_user_pool
UsernameAttributes: # use email as username/login
- 'email'
@chris
chris / authorizer.go
Created May 21, 2021 17:25
Lambda custom authorizer example
package main
import (
"context"
"errors"
"strings"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
@chris
chris / serverless.yml
Created May 3, 2021 03:53
Cognito user pool authorizer definition in Serverless Framework
functions:
myfunc:
handler: bin/myhandler
events:
- http:
path: myapipath
method: get
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
@chris
chris / events.json
Last active November 23, 2020 19:16
Example of events for our API Gateway to DynamoDB API
{
"event": [
{
"time": "2020-06-16T15:22:33Z",
"lng": -122.03053391,
"lat": 37.33180957,
"uuid": "96a6f48c-fe67-4cad-be24-21d6523137f6",
"sensor_name": "CYT523",
"reading_value": 72.9,
"is_active": true