数据未从s3传递到dynamodb

时间:2019-04-17 04:36:11

标签: python-3.x amazon-s3 aws-lambda amazon-dynamodb amazon-cloudwatchlogs

数据没有从S3传递到dynamodb。似乎我缺少了一些东西。如果有人为此要求工作,请帮助我。

我已经编写了一个不会引发任何错误的代码。尽管同时没有将数据传递给dynamodb。似乎我缺少了一些东西。我已经用主键将dynamodb表配置为CN。在txt文件中,第一行是标题,其余行包含数据。但是数据并没有加载到dynamodb。

import boto3

s3 = boto3.client('s3')
dynamodb = boto3.resource('dynamodb','ap-southeast-1')

table=dynamodb.Table('TF')
txtFileReader={};

def txt_reader(event,context):
  bucket_path = event['Records'][0]['s3']['bucket']['name'];
  key_path = event['Records'][0]['s3']['object']['key'];

#value is getting printed for the below 2-prints
  print(bucket_path)
  print(key_path)


  txt_obj = s3.get_object(Bucket=bucket_path,Key=key_path)
  txtFileReader = txt_obj['Body'].read().decode('utf-8').split('\n')

#for below print, data is good
  print(txtFileReader)

#looks like the issue is after defining the batch_write
def batch_write(table_name,txtFileReader):    
  table=dynamodb.Table('TF')
  print(table)

with table.batch_writer() as batch:
   for row in txtFileReader:

     print(txtFileReader)
     batch.put_item(Item = {
            'CN':row.split('|')[0],
            'SN':row.split('|')[1],
            'WF':row.split('|')[2],
            'SEPM':row.split('|')[3],
            'Conf':row.split('|')[4],
            'Last-Check-In':row.split('|')[5]

            })

这是我正在使用的示例文件

CN|SN|WF|sepm|Conf|Last-Check-In 
PCOT|HQL||1|G01|9/3/2018 07:01 
PR2|CND||1|G02|8/29/2018 19:01 
M7|F9M||1|G03|9/3/2018 10:10 
MA|8CG4||1|G04|8/27/2018 15:00

0 个答案:

没有答案