AWS Lambda Python Boto3 – Inserting data into dynamodb throws error ResourceNotFoundException) when calling the PutItem operation: Requested resou",

Question:

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

Asked By: Jason

||

Answers:

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.

Answered By: Coin Graham