简体   繁体   中英

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

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)

在此处输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM