-2

This my Code:

`import boto3
from boto3.dynamodb.conditions import Key

TABLE_NAME = "RegData"

# Creating the DynamoDB Client
dynamodb_client = boto3.client('dynamodb', region_name="us-east-1")

# Creating the DynamoDB Table Resource
dynamodb = boto3.resource('dynamodb', region_name="us-east-1")
table = dynamodb.Table(TABLE_NAME)
response = dynamodb_client.get_item(
    TableName=TABLE_NAME,
    Key={
        'BarCode': {'S': str(10)},
    }
)
print(response['Item'])
`

The Error Massage:

NoCredentialsError                        Traceback (most recent call last)
<ipython-input-85-d5e8f6f0dacd> in <cell line: 1>()
 1 response = dynamodb_client.get_item(
      2     TableName=TABLE_NAME,
      3     Key={
      4         'artist': {'S': str(10)},
      5     }

My Table: enter image description here I tried defining the response part in a function it run smoothly however when I call the function the same error appear

Malak
  • 37
  • 7

1 Answers1

0

Depending on where you run the code from you should set up credentials. Always refrain from hardcoding credentials in your code.

The easiest way if you use a local machine is to use aws configure on the CLI: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html

If you use EC2 or other AWS services then you should use an instance profile role:

https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2_instance-profiles.html

Full documentation here:

https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html

Leeroy Hannigan
  • 11,409
  • 3
  • 14
  • 31