Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pynamodb amazon credential exception

I am following the pynamodb documentation

class Thread(Model):
    class Meta:
        read_capacity_units = 1
        write_capacity_units = 1
        table_name = "Thread"
        region = 'us-west-1'
        host = "http://localhost:8888"

    forum_name = UnicodeAttribute(hash_key=True)
    subject = UnicodeAttribute(range_key=True)
    views = NumberAttribute(default=0)
    replies = NumberAttribute(default=0)
    answered = NumberAttribute(default=0)
    tags = UnicodeSetAttribute()
    last_post_datetime = UTCDateTimeAttribute(null=True)

# Delete the table
# print(Thread.delete_table())

# Create the table
if not Thread.exists():
    Thread.create_table(wait=True)

When i run above code it gives error:

DEBUG:pynamodb.connection.base:Calling DescribeTable with arguments {'TableName': 'Thread'}

and raises exception:

raise TableError("Unable to describe table: {0}".format(e), e)

TableError: Unable to describe table: Unable to locate credentials

How to provide the pynamodb aws_secret_key_id and aws_access key. I am running the example on local computer using dynamodb local.

How I provide the credential information in pynamodb. I did set environment variables of the aws_secret_key_id and aws_access_key but still credential exeception

Is there any way to provide the aws_access_key_id and aws_secret_access_key as a parameter in the pynamodb like bellow example:-

this code working and create the database but i want use the pynamodb library

dynamodb = boto3.resource('dynamodb',
                          region_name='us-west-2',
                          aws_access_key_id="access key",
                          aws_secret_access_key="secret acess key",
                          endpoint_url="http://localhost:8888")
like image 866
Sohaib Ahmed Avatar asked Sep 03 '25 16:09

Sohaib Ahmed


2 Answers

In Meta class, include

aws_access_key_id = "anything"
aws_secret_access_key = "fake"

You can give any fake secret access key and access key.

like image 79
Bhupali Maheshwari Avatar answered Sep 05 '25 09:09

Bhupali Maheshwari


create a file ~/.aws/credentials and enter

[default]
aws_access_key_id = 'foo'
aws_secret_access_key = 'bar

or better still

Unable to locate credentials

like image 45
ewianda Avatar answered Sep 05 '25 10:09

ewianda