"An obligation/a duty, something meant to be done due to a rule or a law" is closer to 義務, for example, "payment of taxes" is 義務.
義理 is more likely an obligation/a duty in relation between people. It often has a nuance of what people should obey as a right action, and it doesn't always have a forced nuance.