Wednesday, March 4, 2020

Export DynamoDB as csv

You must have dynamodb with lots of data and you want o see this in excel file. Dynamodb is a concept without columns but still it can exported in csv. You may have number of tables in dynamodb. Here is a way to export it.
1. Clone following repo from github.
git clone https://github.com/edasque/DynamoDBtoCSV.git
2. Install node based dependencies.
npm install
3. Fill the access key, secret key and region in the file DynamoDBtoCSV/config.json
{
    "accessKeyId": "QWERTNVEXAMPLEMUJMKI",
    "secretAccessKey": "+WSXCD/SdEfExAmPlEJkjKL/KlOiK45Iu",
    "region": "us-east-1"
}
4. Now export tables using following commands.
node dynamoDBtoCSV.js -t tableOne > tableOne.csv
node dynamoDBtoCSV.js -t tableTwo > tableTwo.csv


AWS take backup of all IAM Roles and Policies


If you want to take backup of your all IAM roles and policies, here is solution for you.

1. Configure aws cli with access key and secret key.
aws configure
2. Save all roles and policies in json file
aws iam get-account-authorization-detail > output.json
There are several ways to read this json file using a script. 

Now You have complete data of your role and policies.

No log written in Syslog and auth.log

If you want to check some errors in /var/log/syslog or /var/log/auth.log and you find both files empty, it means system is not able to write logs in both files because of permission issue or any mis configuration. Here is solution for you. 

Solution :
Reconfigure rsyslog
sudo apt-get install --reinstall rsyslog
sudo service rsyslog restart
If still it does not work, issue may be with permissions, check the owner of both files.
ls -l /var/log/syslog
ls -l /var/log/auth.log
Group and owner should be syslog & adm, if owner or group is set as root or anything else, you need to change with following commands
sudo chown syslog:adm /var/log/syslog
sudo chown syslog:adm /var/log/auth.log
Now check if it starts writing logs in both files. Still it does not work, restart the service rsyslog.
sudo service rsyslog restart
it should work now.