Netflix-Skunkworks / aardvark

Aardvark is a multi-account AWS IAM Access Advisor API
Apache License 2.0
472 stars 77 forks source link

Unable to retrieve data from sqlite db #120

Closed jaychan-q closed 4 years ago

jaychan-q commented 4 years ago

I have created the aardvark db (sqlite) and ran the update command to fetch the data. The data is populated as well

/usr/local/bin/aardvark start_api -b 0.0.0.0:5000
[root@ip-10-20-7-230 system]# netstat -anp|grep LISTEN
tcp        0      0 0.0.0.0:5000            0.0.0.0:*               LISTEN      7584/python3   
[root@ip-10-20-7-230 aardvark]# sqlite3 aardvark.db 
SQLite version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> 
sqlite> select count(*) from aws_iam_object;
2425
sqlite> 

healthcheck is passing as well

$ curl http://10.20.7.230:5000/healthcheck && echo
ok

But when i try to fetch data from api i get this error

$ curl http://10.20.7.230:5000/api/1/advisors -X POST
{
  "message": "(sqlite3.OperationalError) no such table: aws_iam_object\n[SQL: SELECT aws_iam_object.id AS aws_iam_object_id, aws_iam_object.arn AS aws_iam_object_arn, aws_iam_object.\"lastUpdated\" AS \"aws_iam_object_lastUpdated\" \nFROM aws_iam_object\n LIMIT ? OFFSET ?]\n[parameters: (100, 0)]\n(Background on this error at: http://sqlalche.me/e/e3q8)"
}

I see the table present as well as values in it. Can you please assist further. Thanks

jaychan-q commented 4 years ago

Also found an interesting thing.

When i start aardvark api server without any parameters, it runs on port 8000 with localhost binding. When i run this command it returns results

curl localhost:8000/api/1/advisors

Not sure why it does not return any data when binded with 0.0.0.0 on port 5000

jaychan-q commented 4 years ago

I found the issue. When running as systemd service i had not specified the working folder where the config.py file was present. Hence the above error. In case if anyone wants to set it as systemd service

[Unit]
Description=Example systemd service.
After=network.target

[Service]
Type=simple
Restart=always
RestartSec=1
User=root
StartLimitBurst=5
StartLimitInterval=10
WorkingDirectory=/root  #specify the path of config.py file
ExecStart= /usr/local/bin/aardvark start_api -b 0.0.0.0 #by default will run listen on port 8000

[Install]
WantedBy=multi-user.target