Skip to content

Commit

Permalink
Merge pull request #32 from jameshy/update-dependencies
Browse files Browse the repository at this point in the history
Update postgres and dependencies
  • Loading branch information
jameshy authored Jun 10, 2021
2 parents 9adf955 + b0159c4 commit 1c19597
Show file tree
Hide file tree
Showing 14 changed files with 633 additions and 316 deletions.
60 changes: 42 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ It can be configured to run periodically using CloudWatch events.

1. Create an AWS lambda function:
- Author from scratch
- Runtime: Node.js 12.x
2. Configuration -> Function code:
- Code Entry Type: Upload a .zip file
- Upload ([pgdump-aws-lambda.zip](https://github.com/jameshy/pgdump-aws-lambda/releases/latest))
- Basic Settings -> Timeout: 15 minutes
- Runtime: Node.js 14.x
2. tab "Code" -> "Upload from" -> ".zip file":
- Upload ([pgdump-aws-lambda.zip](https://github.com/jameshy/pgdump-aws-lambda/releases/latest))
- tab "Configuration" -> "General Configuration" -> "Edit"
- Timeout: 15 minutes
- Edit the role and attach the policy "AmazonS3FullAccess"
- Save
3. Configuration -> Execution role
- Edit the role and attach the policy "AmazonS3FullAccess"
4. Test
3. Test
- Create new test event, e.g.:
```json
{
Expand All @@ -33,7 +32,7 @@ It can be configured to run periodically using CloudWatch events.
```
- *Test* and check the output

5. Create a CloudWatch rule:
4. Create a CloudWatch rule:
- Event Source: Schedule -> Fixed rate of 1 hour
- Targets: Lambda Function (the one created in step #1)
- Configure input -> Constant (JSON text) and paste your config (as per step #4)
Expand Down Expand Up @@ -93,10 +92,10 @@ Support for this can be enabled my making your Cloudwatch Event look like this.
{
"PGDATABASE": "dbname",
"PGUSER": "postgres",
"USE_IAM_AUTH": true,
"PGHOST": "host",
"S3_BUCKET" : "db-backups",
"ROOT": "hourly-backups"
"ROOT": "hourly-backups",
"USE_IAM_AUTH": true
}
```

Expand All @@ -107,13 +106,38 @@ If you still provide it, it will be ignored.

#### Bundling a new `pg_dump` binary
1. Launch an EC2 instance with the Amazon Linux 2 AMI
2. Connect via SSH and [Install PostgreSQL using yum](https://stackoverflow.com/questions/55798856/deploy-postgres11-to-elastic-beanstalk-requires-etc-redhat-release).
3. Locally, create a new directory for your pg_dump binaries: `mkdir bin/postgres-11.6`
3. Copy the binaries
- `scp -i <aws PEM> ec2-user@<EC2 Instance IP>:/usr/bin/pg_dump ./bin/postgres-11.6/pg_dump`
- `scp -i <aws PEM> ec2-user@<EC2 Instance IP>:/usr/lib64/{libcrypt.so.1,libnss3.so,libsmime3.so,libssl3.so,libsasl2.so.3,liblber-2.4.so.2,libldap_r-2.4.so.2} ./bin/postgres-11.6/`
- `scp -i <aws PEM> ec2-user@<EC2 Instance IP>:/usr/pgsql-11/lib/libpq.so.5 ./bin/postgres-11.6/libpq.so.5`
4. When calling the handler, pass the environment variable `PGDUMP_PATH=postgres-11.6` to use the binaries in the bin/postgres-11.6 directory.
2. Connect via SSH and:
```bash

# install postgres 13
sudo amazon-linux-extras install epel

sudo tee /etc/yum.repos.d/pgdg.repo<<EOF
[pgdg13]
name=PostgreSQL 13 for RHEL/CentOS 7 - x86_64
baseurl=https://download.postgresql.org/pub/repos/yum/13/redhat/rhel-7-x86_64
enabled=1
gpgcheck=0
EOF

sudo yum install postgresql13 postgresql13-server

exit
```

#### Download the binaries

```bash
scp -i ~/aws.pem ec2-user@18.157.84.236:/usr/bin/pg_dump ./bin/postgres-13.3/pg_dump
scp -i ~/aws.pem ec2-user@18.157.84.236:/usr/lib64/{libcrypt.so.1,libnss3.so,libsmime3.so,libssl3.so,libsasl2.so.3,liblber-2.4.so.2,libldap_r-2.4.so.2} ./bin/postgres-13.3/
scp -i ~/aws.pem ec2-user@18.157.84.236:/usr/pgsql-13/lib/libpq.so.5 ./bin/postgres-13.3/libpq.so.5
```
3. To use the new postgres binary pass PGDUMP_PATH in the event:
```json
{
"PGDUMP_PATH": "bin/postgres-13.3"
}
```

#### Creating a new function zip

Expand Down
Binary file added bin/postgres-13.3/libcrypt.so.1
Binary file not shown.
Binary file added bin/postgres-13.3/liblber-2.4.so.2
Binary file not shown.
Binary file added bin/postgres-13.3/libldap_r-2.4.so.2
Binary file not shown.
Binary file added bin/postgres-13.3/libnss3.so
Binary file not shown.
Binary file added bin/postgres-13.3/libpq.so.5
Binary file not shown.
Binary file added bin/postgres-13.3/libsasl2.so.3
Binary file not shown.
Binary file added bin/postgres-13.3/libsmime3.so
Binary file not shown.
Binary file added bin/postgres-13.3/libssl3.so
Binary file not shown.
Binary file added bin/postgres-13.3/pg_dump
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path')
// default config that is overridden by the Lambda event
module.exports = {
S3_REGION: 'eu-west-1',
PGDUMP_PATH: path.join(__dirname, '../bin/postgres-11.6'),
PGDUMP_PATH: path.join(__dirname, '../bin/postgres-13.3'),
// maximum time allowed to connect to postgres before a timeout occurs
PGCONNECT_TIMEOUT: 15,
USE_IAM_AUTH: false
Expand Down
Loading

0 comments on commit 1c19597

Please sign in to comment.