Skip to content

Commit 1c19597

Browse files
authored
Merge pull request #32 from jameshy/update-dependencies
Update postgres and dependencies
2 parents 9adf955 + b0159c4 commit 1c19597

14 files changed

+633
-316
lines changed

README.md

+42-18
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ It can be configured to run periodically using CloudWatch events.
1111

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

36-
5. Create a CloudWatch rule:
35+
4. Create a CloudWatch rule:
3736
- Event Source: Schedule -> Fixed rate of 1 hour
3837
- Targets: Lambda Function (the one created in step #1)
3938
- Configure input -> Constant (JSON text) and paste your config (as per step #4)
@@ -93,10 +92,10 @@ Support for this can be enabled my making your Cloudwatch Event look like this.
9392
{
9493
"PGDATABASE": "dbname",
9594
"PGUSER": "postgres",
96-
"USE_IAM_AUTH": true,
9795
"PGHOST": "host",
9896
"S3_BUCKET" : "db-backups",
99-
"ROOT": "hourly-backups"
97+
"ROOT": "hourly-backups",
98+
"USE_IAM_AUTH": true
10099
}
101100
```
102101

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

108107
#### Bundling a new `pg_dump` binary
109108
1. Launch an EC2 instance with the Amazon Linux 2 AMI
110-
2. Connect via SSH and [Install PostgreSQL using yum](https://stackoverflow.com/questions/55798856/deploy-postgres11-to-elastic-beanstalk-requires-etc-redhat-release).
111-
3. Locally, create a new directory for your pg_dump binaries: `mkdir bin/postgres-11.6`
112-
3. Copy the binaries
113-
- `scp -i <aws PEM> ec2-user@<EC2 Instance IP>:/usr/bin/pg_dump ./bin/postgres-11.6/pg_dump`
114-
- `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/`
115-
- `scp -i <aws PEM> ec2-user@<EC2 Instance IP>:/usr/pgsql-11/lib/libpq.so.5 ./bin/postgres-11.6/libpq.so.5`
116-
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.
109+
2. Connect via SSH and:
110+
```bash
111+
112+
# install postgres 13
113+
sudo amazon-linux-extras install epel
114+
115+
sudo tee /etc/yum.repos.d/pgdg.repo<<EOF
116+
[pgdg13]
117+
name=PostgreSQL 13 for RHEL/CentOS 7 - x86_64
118+
baseurl=https://download.postgresql.org/pub/repos/yum/13/redhat/rhel-7-x86_64
119+
enabled=1
120+
gpgcheck=0
121+
EOF
122+
123+
sudo yum install postgresql13 postgresql13-server
124+
125+
exit
126+
```
127+
128+
#### Download the binaries
129+
130+
```bash
131+
scp -i ~/aws.pem [email protected]:/usr/bin/pg_dump ./bin/postgres-13.3/pg_dump
132+
scp -i ~/aws.pem [email protected]:/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/
133+
scp -i ~/aws.pem [email protected]:/usr/pgsql-13/lib/libpq.so.5 ./bin/postgres-13.3/libpq.so.5
134+
```
135+
3. To use the new postgres binary pass PGDUMP_PATH in the event:
136+
```json
137+
{
138+
"PGDUMP_PATH": "bin/postgres-13.3"
139+
}
140+
```
117141

118142
#### Creating a new function zip
119143

bin/postgres-13.3/libcrypt.so.1

40.1 KB
Binary file not shown.

bin/postgres-13.3/liblber-2.4.so.2

60.3 KB
Binary file not shown.

bin/postgres-13.3/libldap_r-2.4.so.2

356 KB
Binary file not shown.

bin/postgres-13.3/libnss3.so

1.17 MB
Binary file not shown.

bin/postgres-13.3/libpq.so.5

322 KB
Binary file not shown.

bin/postgres-13.3/libsasl2.so.3

118 KB
Binary file not shown.

bin/postgres-13.3/libsmime3.so

156 KB
Binary file not shown.

bin/postgres-13.3/libssl3.so

366 KB
Binary file not shown.

bin/postgres-13.3/pg_dump

404 KB
Binary file not shown.

lib/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const path = require('path')
33
// default config that is overridden by the Lambda event
44
module.exports = {
55
S3_REGION: 'eu-west-1',
6-
PGDUMP_PATH: path.join(__dirname, '../bin/postgres-11.6'),
6+
PGDUMP_PATH: path.join(__dirname, '../bin/postgres-13.3'),
77
// maximum time allowed to connect to postgres before a timeout occurs
88
PGCONNECT_TIMEOUT: 15,
99
USE_IAM_AUTH: false

0 commit comments

Comments
 (0)