Skip to content

Instantly share code, notes, and snippets.

@jtsaito
jtsaito / api-gateway-signed-request-ruby.MD
Last active December 2, 2022 11:17
Signing requests for AWS API Gateway in Ruby

The AWS API Gateway supports signed requests as follows. The API Gateway client can use IAM credentials to sign a request in two steps:

  1. The original request headers and body are signed using the SDK supplied by AWS and the credentials
  2. The signature sets the X-Amz-SignedHeaders header

In practice, there are two ways for signing from a Ruby client using the AWS SDK: (1) signing with a Faraday plugin, (2) creating a Specific Gateway client using the Seahorse API declaration.

Here is a code snippet for the more quick and dirty Faraday solution.

Using Python w/ Minecraft on Ubuntu

These instructions should work on any Ubuntu-based OS, but have only been tested on GalliumOS.

Install required packages

Copy and paste the following line into a terminal and press enter to install all the dependencies (you might already have some installed):

sudo apt update
sudo apt install python-software-properties python3 python3-pip idle3 git
sudo apt install openjdk-8-jre-headless openjdk-8-jdk maven
@jtsaito
jtsaito / readme.md
Created January 17, 2021 16:56 — forked from noahcoad/readme.md
Code Minecraft with Python on Mac OSX

Code Minecraft with Python on Mac OSX

Here's a step-by-step to get started scripting Minecraft with Python on Mac OSX

@jtsaito
jtsaito / index.js.md
Last active September 19, 2018 10:26
AWS Lambda Handler for node8.10 with DynamoDB client call

Exmaple handler given a DynamoDB table your-table with hash key uuid.

const AWS = require('aws-sdk');
AWS.config.update({region: 'eu-west-1'});
const dynamo = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'});

exports.handler = async (event) => {
    //console.log('Received event:::', JSON.stringify(event));
 

Setting up a Docker Registry with Let's Encrypt TLS support

This gist describes how to set up a private Docker Registry on an AWS EC2 instance and how to secure it with TLS using a certificate by Let's Encrypt.

A Docker registry is a server side application that stores and lets you distribute Docker images. It runs in an own Docker container and the image is freely available. Let's Encrypt is a Certificate Authority that gives away TLS certificates for free.

0. Prerequisites

We require the following three items to be set up correctly before we start.

@jtsaito
jtsaito / dynamodb_lambda.MD
Last active January 31, 2018 18:33
AWS DyndamoDB and Lambda

This code example briefly describes how to store data to and retrieve data from DynamoDB using two AWS Lambdas. In this example we assume a DynamoDB tale test-can-learn with String key user_uuid in region eu-west-1. As a bonus, we show how to make the read access available as RESTful resource with AWS' API Gateway.

1. Setup Lambdas

Skip Lambda templates and craete the Lambdas custom. Then assign the Basic with DynamoDB role to the Lambda.

2. Lambda writing to DynamoDB

var AWS = require('aws-sdk');
var dynamodb = new AWS.DynamoDB({
  region: 'eu-west-1'
@jtsaito
jtsaito / trans.sh
Last active May 14, 2017 12:34
Transcode 720 to 1080 with ffmpeg
#!/bin/bash
# This script downsizes video files from 1080 to 720 resolution using ffmpeg.
# It expects input files in ./movies and an output dir ./720.
transcode ()
{
file=$1
indir=$2
outdir=$3
@jtsaito
jtsaito / terraform-github-acc-test.md
Created March 2, 2017 11:36
Terraform Acc Test ouptput: Github Repository Resource: Acc Test failing locally
jsaito@jahns-mbp > ~/projects/go/src/github.com/hashicorp/terraform > GITHUB_TOKEN=<REMOVED> GITHUB_ORGANIZATION=Bassetfroggs GITHUB_TEST_USER=servicejts GITHUB_TEST_COLLABORATOR=jsaito make testacc TEST=./builtin/providers/github
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/03/02 11:56:57 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/github -v  -timeout 120m
=== RUN   TestProvider
--- PASS: TestProvider (0.00s)
=== RUN   TestProvider_impl
--- PASS: TestProvider_impl (0.00s)
@jtsaito
jtsaito / .md
Last active February 20, 2017 15:34
Error output: Terraform AWS Inspector Assessment Target bug

On terraform planning to update the (we removed some json content and marked it <REMOVED>:

Path: terraform.tfplan
~ aws_opsworks_rails_app_layer.bookshelf-app
    custom_json: "<REMOVED>"

~ aws_inspector_assessment_target.inspector
    resource_group_arn: "arn:aws:inspector:eu-west-1:390571511014:resourcegroup/0-PQ6fNHHt" => "${aws_inspector_resource_group.inspector.arn}"
@jtsaito
jtsaito / aws-lambda-client.MD
Created April 13, 2016 19:34
AWS Lambda GUI bug for zip upload

AWS Lambda allows uploading from S3. The S3 object can be specified in the console. There is bug when the Lambda and the S3 bug are both in AWS region eu-central-1.

The S3 console gives the following resource url: https://s3.eu-central-1.amazonaws.com/xzy/lambda_function.zip. Inputing the url raises an error by the Lambda GUI.

The usual S3 endpoint domain is s3-{region-name}.amazonaws.com (documentation). The problem is that eu-central-1 region is deviating from this scheme, allowing s3.eu-central-1.amazonaws.com (note the dot)). This endpoint is given in by the console. Copy-and-pasting it reveals the incorrect validation in the Lambda GUI.