Exit codes in Python

0 and 1 are the exit codes.

exit(0) means a clean exit without any errors / problems

exit(1) means there was some issue / error / problem and that is why the program is exiting.

This is not Python specific and is pretty common. A non-zero exit code is treated as an abnormal exit, and at times, the error code indicates what the problem was. A zero error code means a successful exit.

This is useful for other programs, shell, caller etc. to know what happened with your program and proceed accordingly.

For the record, you can use POSIX standard exit codes defined here.

Example:

import sys, os

try:
    config()
except:
    sys.exit(os.EX_CONFIG) 
try:
    do_stuff()
except:
    sys.exit(os.EX_SOFTWARE)
sys.exit(os.EX_OK) # code 0, all ok
Advertisements

Dynamodb: How to run dynamodb locally

DynamoDb is a cloud managed server provided by AWS – Amazon web service. Technically, you cannot install and manage it on your own for your production system. However for testing purpose, AWS provides the ways to run it locally and avoid hitting cloud service all the time to save some money.
The easiest way is to pull docker image and run it locally
Follow below steps to run dynamodb locally
# pull image from docker hub provided by AWS – https://hub.docker.com/r/amazon/dynamodb-local/

docker pull amazon/dynamodb-local
# run image
docker run -p 8000:8000 amazon/dynamodb-local
Hit this url on browser  to test dynamodb is working