Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use access credentials in code instead of environment variables with PynamoDB

I have a python app that uses several services from aws. I have one access key and secret for each service. For most of the services I use boto and don't need AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY in the environment. For dynamoDB I use pynamoDB and I have no idea how to set the credentials without these variables.

I want to standardize the credential in a settings file to avoid errors like clash of credentials.

Is this possible? If so, how is it done?

like image 201
joaonrb Avatar asked Oct 14 '25 18:10

joaonrb


1 Answers

From the PynamoDB documentation:

PynamoDB uses botocore to interact with the DynamoDB API. Thus, any method of configuration supported by botocore works with PynamoDB. For local development the use of environment variables such as AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY is probably preferable. You can of course use IAM users, as recommended by AWS. In addition EC2 roles will work as well and would be recommended when running on EC2.

Note that if all the services you are interacting with are within the same AWS account, then the preferred way to supply credentials would be to create a single IAM account with all the necessary permissions attached, or an IAM role if the code is running on EC2 or Lambda.

like image 132
Mark B Avatar answered Oct 17 '25 07:10

Mark B