I am working on a Boto3 script that can load the attributes from Cloudtrail into Dynamodb. The format of my cloudtrail logs is JSON. I am fairly new to DynamoDB and I am not sure where I am making a mistake. I’m trying to store “S3BucketName” as well as the name of the bucket which is “goodbucket3”. Name for the cloudtrail is “GoodTrail”.This is what I have come up with so far. I am getting this error “ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the PutItem operation: Requested resource not found”
JavaScript
x
32
32
1
import boto3
2
3
dynamodb = boto3.resource('dynamodb')
4
5
table =dynamodb.create_table(
6
TableName='GoodTable',
7
AttributeDefinitions=[
8
{
9
"AttributeName": "S3BucketName",
10
"AttributeType": "S"
11
}
12
],
13
KeySchema=[
14
{
15
"AttributeName": "S3BucketName",
16
"KeyType": "HASH"
17
}
18
],
19
ProvisionedThroughput={
20
"ReadCapacityUnits": 1,
21
"WriteCapacityUnits": 1
22
}
23
)
24
25
table = dynamodb.Table('GoodTable')
26
response = table.put_item(
27
Item= {
28
'S3BucketName': 'some-bucket-name',
29
'content': f'{path}',
30
}
31
)
32
Advertisement
Answer
Your table
is just a dictionary. It is not dynamodb’s table object.
To rectify the issue:
JavaScript
1
15
15
1
import boto3
2
3
dynamodb_res = boto3.resource('dynamodb')
4
5
table = dynamodb_res.Table('GoodTable')
6
7
response = table.put_item(
8
Item= {
9
'S3BucketName': 'some-bucket-name',
10
'content': f'{path}',
11
}
12
)
13
14
print(response)
15
Based on your definition, you don’t have any id
. Your primary key in your table is S3BucketName
, not id
.