1

AWS is buggy I think. I didn't make any change to the code. Today it is working fine. I struggled all day

I am reading the content of a file from S3 and trying to insert data into Dynamodb table. Everything works right up until inserting data into the dynamodb table. The table exists but it says resource not found Both Lambda and Dynamodb exist in the same region.

It says: "errorMessage": "An error occurred (ResourceNotFoundException) when calling the PutItem operation: Requested resource not found", "errorType": "ResourceNotFoundException",

I tried describe the table. that also throws error

dbclient = boto3.session('dynamodb')
response = dbclient.describe_table(TableName='USBCallCenterTable')
print(response)

import json
import boto3
from pprint import pprint

def lambda_handler(event, context):   
    session = boto3.session.Session()   
    s3_client = session.client('s3')


    for record in event['Records']:
        bucket_name=record['s3']['bucket']['name']
        key_name = record['s3']['object']['key']
        #pprint(dir(record))
        #print(bucket,key)
    
    response =  s3_client.get_object(Bucket = bucket_name, Key = key_name)

    #convert streaming data to byte
    content = response['Body'].read()

    ##convert the byte into string
    data_inString = content.decode('UTF-8')

    ##convert the string data into dictionary 
    data_inDictionary = json.loads(data_inString)
    print(data_inDictionary)

    dynamodbtable = boto3.resource('dynamodb')
    table = dynamodbtable.Table('customer')
    table.put_item(Item=data_inDictionary)

enter image description here

14
  • can you give exact error ? with traceback ? Commented Aug 30, 2022 at 21:48
  • from the initial error, it seems like it role associated with lambda function don't have permission or that table is not exists. Commented Aug 30, 2022 at 21:51
  • Nilesh. this is the stack trace Commented Aug 30, 2022 at 21:51
  • I gave AmazonDynamoDBFullAccess policy to the role and the table exists. I am able to add data manually thru the console to the table Commented Aug 30, 2022 at 21:52
  • 1
    Make sure you are using the correct region in the lambda handler. Commented Aug 30, 2022 at 21:57

1 Answer 1

1

I created a plain lambda and table in a region and was able to run your python code above successfully. There does not appear to be an error in your code.

Note that when I first deployed your code, I forgot to update the table name and received the exact same error you received. Once I fixed the table name it worked as expected.

Sign up to request clarification or add additional context in comments.

1 Comment

thank You Coin. It worked fine without any problem today

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.