Last active
April 21, 2020 13:32
-
-
Save tarrynn/cc2d9b296a0fbaef04edd26edb968a8a to your computer and use it in GitHub Desktop.
Revisions
-
tarrynn revised this gist
Apr 21, 2020 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,8 +23,10 @@ Dockerfile FROM lambci/lambda:build-ruby2.5 RUN yum install -y \ https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/postgresql10-libs-10.10-1PGDG.rhel6.x86_64.rpm RUN yum install -y \ https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/postgresql10-10.10-1PGDG.rhel6.x86_64.rpm RUN yum install -y postgresql10-devel RUN gem update bundler -
tarrynn revised this gist
Apr 20, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -68,11 +68,11 @@ DB_PWD = ENV['DB_PWD'] def main(event:, context:) conn = PG::Connection.new( :host => DB_HOST, :dbname => DB_NAME, :port => DB_PORT, :user => DB_USER, :password => DB_PWD ) 20.times do |n| conn.exec( "refresh materialized view stuff;" ) sleep 2.7 end { sql: 'refresh materialized view stuff' } end -
tarrynn revised this gist
Apr 20, 2020 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -55,6 +55,8 @@ BUNDLED WITH 2.0.1 handler.rb require 'pg' DB_HOST = ENV['DB_HOST'] -
tarrynn created this gist
Apr 20, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,76 @@ README ## Setup runtime for this lambda function 1. `docker build -t lambda-ruby2.5-postgresql10 .` to create an environment in which we can build gems with native extensions that will run properly on lambda 2. `docker run --rm -it -v $PWD:/var/task -w /var/task lambda-ruby2.5-postgresql10` to run the docker container with a bash terminal 3. Run the following inside the bash terminal opened above `bundle config --local build.pg --with-pg-config=/usr/pgsql-10/bin/pg_config` inside the bash terminal opened above `bundle config --local silence_root_warning true` `bundle install --path vendor/bundle --clean` `mkdir -p /var/task/lib` `cp -a /usr/pgsql-10/lib/*.so.* /var/task/lib/` ## Deploy to lambda (after the above) 1. `zip -q -r package.zip * && aws lambda update-function-code --function-name $PROJECT_NAME --zip-file 'fileb://package.zip'` Dockerfile FROM lambci/lambda:build-ruby2.5 RUN yum install -y \ https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/pgdg-redhat10-10-2.noarch.rpm RUN sed -i "s/rhel-\$releasever-\$basearch/rhel-6.9-x86_64/g" "/etc/yum.repos.d/pgdg-10-redhat.repo" RUN yum install -y postgresql10-devel RUN gem update bundler CMD "/bin/bash" Gemfile source "https://rubygems.org" gem "pg" Gemfile.lock GEM remote: https://rubygems.org/ specs: pg (1.1.4) PLATFORMS ruby DEPENDENCIES pg BUNDLED WITH 2.0.1 require 'pg' DB_HOST = ENV['DB_HOST'] DB_PORT = ENV['DB_PORT'] DB_NAME = ENV['DB_NAME'] DB_USER = ENV['DB_USER'] DB_PWD = ENV['DB_PWD'] def main(event:, context:) conn = PG::Connection.new( :host => DB_HOST, :dbname => DB_NAME, :port => DB_PORT, :user => DB_USER, :password => DB_PWD ) 20.times do |n| conn.exec( "refresh materialized view element_stock_create_by_date_view;" ) sleep 2.7 end { sql: 'refresh materialized view element_stock_create_by_date_view' } end