-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcriar_conta.py
58 lines (47 loc) · 1.5 KB
/
criar_conta.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import json
import logging
import psycopg2
import rds_config
def main(event, context):
body = json.loads(event["body"])
logger = logging.getLogger()
logger.setLevel(logging.INFO)
# rds settings
rds_host = rds_config.db_host
name = rds_config.db_username
password = rds_config.db_password
db_name = rds_config.db_name
connection = psycopg2.connect(
database=db_name,
user=name,
password=password,
host=rds_host,
port='5432'
)
cursor = connection.cursor()
try:
cursor.execute("""
CREATE TABLE IF NOT EXISTS conta_corrente (
id serial PRIMARY KEY,
agencia integer,
numero_conta integer,
saldo numeric(15,2),
numero_cartao bigint
);
""")
cursor.execute(f"""
insert into conta_corrente(agencia, numero_conta, saldo, numero_cartao)
values ({body["agencia"]}, {body["numeroConta"]}, {body["saldo"]}, {body["numeroCartao"]});
""")
connection.commit()
except psycopg2.Error as e:
connection.rollback()
logger.error("Error while inserting", e)
body = {
"mensagem": "Conta incluida com sucesso"
}
response = {
"statusCode": 200,
"body": json.dumps(body)
}
return response