Skip to content

Commit 9cf9b41

Browse files
authored
fix RDS test (#240)
1 parent cd1ccea commit 9cf9b41

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

rds-db-queries/query.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import os
2+
import time
3+
24
import boto3
35
import psycopg2
46

5-
RDS_ENDPOINT = os.environ.get('RDS_ENDPOINT') or 'http://localhost:4566'
7+
RDS_ENDPOINT = os.environ.get("RDS_ENDPOINT") or "http://localhost:4566"
68

79

810
def run_queries(instance):
9-
print('Run DB queries against RDS instance %s' % instance['DBInstanceIdentifier'])
10-
port = instance['Endpoint']['Port']
11-
conn = psycopg2.connect("dbname=test user=test password='test' host=localhost port=%s" % port)
11+
print("Run DB queries against RDS instance %s" % instance["DBInstanceIdentifier"])
12+
port = instance["Endpoint"]["Port"]
13+
conn = psycopg2.connect(
14+
"dbname=test user=test password='test' host=localhost port=%s" % port
15+
)
1216
with conn.cursor() as cur:
13-
cur.execute('CREATE TABLE person ("id" INTEGER, "name" VARCHAR not null, PRIMARY KEY ("id"))')
17+
cur.execute(
18+
'CREATE TABLE person ("id" INTEGER, "name" VARCHAR not null, PRIMARY KEY ("id"))'
19+
)
1420
cur.execute("INSERT INTO person VALUES (1, 'Jane')")
1521
cur.execute("INSERT INTO person VALUES (2, 'Alex')")
1622
cur.execute("INSERT INTO person VALUES (3, 'Maria')")
@@ -21,28 +27,31 @@ def run_queries(instance):
2127

2228

2329
def create_db():
24-
print('Creating RDS DB instance')
30+
print("Creating RDS DB instance")
2531
client = connect_rds()
26-
instance = client.create_db_instance(Engine='postgres', DBInstanceClass='c1', DBInstanceIdentifier='i1')
27-
return instance['DBInstance']
32+
instance = client.create_db_instance(
33+
Engine="postgres", DBInstanceClass="c1", DBInstanceIdentifier="i1"
34+
)
35+
return instance["DBInstance"]
2836

2937

3038
def delete_db(instance):
31-
inst_id = instance['DBInstanceIdentifier']
32-
print('Deleting RDS DB instance %s' % inst_id)
39+
inst_id = instance["DBInstanceIdentifier"]
40+
print("Deleting RDS DB instance %s" % inst_id)
3341
client = connect_rds()
3442
client.delete_db_instance(DBInstanceIdentifier=inst_id)
3543

3644

3745
def connect_rds():
38-
return boto3.client('rds', endpoint_url=RDS_ENDPOINT)
46+
return boto3.client("rds", endpoint_url=RDS_ENDPOINT)
3947

4048

4149
def main():
4250
instance = create_db()
51+
time.sleep(7) # wait for the instance to be ready
4352
run_queries(instance)
4453
delete_db(instance)
4554

4655

47-
if __name__ == '__main__':
56+
if __name__ == "__main__":
4857
main()

0 commit comments

Comments
 (0)