Skip to content

learn to execute bash {pg_dump & aws s3 cp } on lambda

Notifications You must be signed in to change notification settings

thapakazi/learn_lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

learn to run pg_dump & aws s3 cp on lambda

Summary

With this repo, I learned:

  • layers on lambda, versioning them
  • how to get custom runtime over lambda working
  • blend all free stuffs on internet to play along
  • storage classes on S3, pricing

Arch

  • [ lambda ]
    • layer1: pg_dump runner (I named bash-runner, don’t know why)
    • layer2: awscli
    • script: ~main.sh~ with handler function calling other dependent functions
    • env: ~.env~ file housing the secrets, I didn’t know lambda also provides place to put env vars #reviselater
  • pg_dump <– [pg@play-with-docker]:5432 via ngrok
    1. aws s3 cp dump.sql -> s3 bucket

Step for reproduction

you have been warned, please try this at home ;)

If you wanna do stupid thing like me here are you steps of reproduction:

  1. Preparation:
    1. get free aws account by filling form at end
    2. get a pg running available public to world ( I am not doing lambda in vpc for now) some how, I will write about it if necessary. I managed to do it with Play with docker + ngrok fusion
    3. configure things needed for lambda {iam role}, & s3 bucket(create new if necessary, and allow lambda role to write to it). For sake of simplicity, I gave full control for time being. (lambda full, and s3fullaccess)
  2. Execution:
    1. create a lambda layers
      1. layer for pg_dump
      2. layer for awscli

    lol, I revised this,we have a Makefile now :) make build_layers

  3. Deployment
    • create lambda layers

      ./demo/layers.png

    • deploy lambda function(main.sh)

      ./demo/editor.png

    I have a recorded my screen for demo, I will share later.

Useful Resources:

Meta

I need a pg quick

quick_pg(){
    cat > /tmp/secrets <<EOF
POSTGRES_DB=mydb
POSTGRES_USER=my_user
POSTGRES_PASSWORD=uGbwtA76uXD2
EOF
    docker run --rm -it --env-file /tmp/secrets -p5432:5432 postgres:11-alpine
}

About

learn to execute bash {pg_dump & aws s3 cp } on lambda

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published