6

I am bit new to AWS and DynamoDB. My aim is to embed a small piece of code. The problem I am facing is how to make a connection in python code. I made a connection using AWS cli and then entering access ID and key. But how to do it in my code as i wish to deploy my code on other systems.

Thanks in advance !!

1
  • got it ! using dynamodb = boto3.resource('dynamodb',region_name='eu-west-1',aws_access_key_id='',aws_secret_access_key='') Commented Feb 6, 2018 at 15:36

1 Answer 1

9

First of all read documentation for boto3 dynamo, it's pretty simple:

http://boto3.readthedocs.io/en/latest/reference/services/dynamodb.html

If you want to provide access keys while connecting to dynamo, you can do the following:

client = boto3.client('dynamodb',aws_access_key_id='yyyy', aws_secret_access_key='xxxx', region_name='***')

But, remember, it is against best practices from security perspective to store such keys within the code.

For best security efforts use IAM roles. boto3 driver will automatically consume IAM role if it is attached to the instance. Link to the docs: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html

Also, if IAM roles is to complicated, you can install and aws-cli and run aws configure on your server, and boto3 will use the key from here (less secure than a previous approach).

After implementing one of the options, you can connect to DynamoDB without the keys from code:

client = boto3.client('dynamodb', region_name='***')
Sign up to request clarification or add additional context in comments.

1 Comment

thanks a lot ! just got it. dig some research my self. Appreciate your effort

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.