Skip to content

Instantly share code, notes, and snippets.

View metaskills's full-sized avatar
🧠
Adding Digital Intelligence

Ken Collins metaskills

🧠
Adding Digital Intelligence
View GitHub Profile
@metaskills
metaskills / production.rb
Created May 31, 2021 14:09
Using Rack Deflater in Lambda with Rails
# In config/environments/production.rb
config.middleware.insert_after ActionDispatch::Static, Rack::Deflater, sync: false
@metaskills
metaskills / deploy.yml
Created March 20, 2021 17:27
Private GitHub ECR Action Abstract
- name: Checkout (private actions)
uses: daspn/private-actions-checkout@v2
with:
actions_list: '["myorg/create-ecr-repo@main"]'
ssh_private_key: ${{ secrets.MYORG_GITHUB_SSH_KEY }}
- name: ECR
uses: ./.github/actions/create-ecr-repo
with:
stage: ${{ github.event.inputs.stage }}
repo-name: myorg/myapp
@metaskills
metaskills / proposal.md
Created March 9, 2021 10:30
Modernizing Rails with Serverless Containers - RailsConf 2021 Proposal

Abstract

Rails was made for servers. From web servers to background jobs, orchestrating the complexity of Rails in our cloud's infrastructure is hard work. We can not Kubernetes our way out of it either. There is a better way...one that is not well understood. With AWS Lambda and event-driven methodologies, we can fundamentally reinvent our beloved framework. It can change, and indeed thrive, without servers.

For Review Committee

Details

AWS Lambda is a commoditized compute platform of the future. Deeply integrated within AWS, it allows your Rails architecture to be completely reimagined atop fully managed infrastructure resources like API Gateway, SQS, S3, CloudWatch, VPC NAT Gateways, IAM, and so much more. As we explore Rails on Lambda, a pattern of evaporating concerns will become a common theme.

@metaskills
metaskills / template.yml
Last active January 15, 2021 19:47
Lambdakiq Lamby Template
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: LambdakiqRail
Parameters:
RailsEnv:
Type: String
Default: staging
AllowedValues:
@metaskills
metaskills / omniauth.rb
Created November 20, 2020 22:23
AWS SSO Omniauth
metadata = Rails.root.join 'config', 'myapp_ins-8d2c1e14da9ca2bc.xml'
idpdata = File.read(metadata)
parser = OneLogin::RubySaml::IdpMetadataParser.new
SAML_SETTINGS = parser.parse_to_hash(idpdata)
Rails.application.config.middleware.use OmniAuth::Builder do
provider :saml, SAML_SETTINGS.merge(
issuer: 'myapp'
)
end
# Setup
aws application-autoscaling \
register-scalable-target \
--service-namespace "lambda" \
--resource-id "function:myapp:live" \
--min-capacity 5 \
--max-capacity 100 \
--scalable-dimension "lambda:function:ProvisionedConcurrency"
@metaskills
metaskills / capysetup.rb
Created September 28, 2020 22:45
Rails Capybara System Tests Setup
# Gemfile
gem 'selenium-webdriver'
# test/application_system_test_case.rb (or capy setup file)
require 'test_helper'
Capybara.server = :webrick
Webdrivers::Chromedriver.required_version = '2.36'
driver_path = Webdrivers::Chromedriver.update
@metaskills
metaskills / layer_downloader.rb
Created July 25, 2020 02:55
Useful for Ruby/Docker SAM Projects
require 'yaml'
require 'open-uri'
require 'aws-sdk-lambda'
class LayerDownloader
def download
File.open(zip_file, 'wb') do |f|
URI.open(location) { |zip| f.write(zip.read) }
end
@metaskills
metaskills / event.json
Created June 16, 2020 13:26
Sample API Gateway HTTP API Version 1 Event
{
"version": "1.0",
"resource": "$default",
"path": "/",
"httpMethod": "GET",
"headers": {
"Content-Length": "0",
"Host": "myawesomelambda.example.com",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15",
"X-Amzn-Trace-Id": "Root=1-5e7fe714-fee6909429159440eb352c40",
@metaskills
metaskills / wizard.sh
Last active May 10, 2020 13:08
Learning to Program The Cloud
insert_file_over_pattern () {
dline=$(sed -n "/${2}/=" $1)
rline=$(expr $dline - 1)
sed --in-place -e "${dline}d" $1
sed --in-place "${rline}r ../inserts/${1}" $1
}
insert_file_over_pattern 'config/application.rb' 'Bundler.require'