Regarding the order of reflection in DynamoDB and the deletion of title lines

Asked 2 years ago, Updated 2 years ago, 137 views

The order of registration to the DynamoDB table is
"0→1→2→5→3→4→6→11→10→8→7→9"

Isn't it the order of numbers after "emp_data"?
Also, CSV contains title lines, so if you want to retrieve them from the second line,
What kind of code should I add?
Thank you for your cooperation.

import boto3
 
# S3, Preparing to Connect to the DynamoDB Table
s3_client=boto3.client("s3")
dynamicb = boto3.resource("dynamodb")
table=dynamodb.Table("test-jsonlog")
 
deflambda_handler(event, context):
 
    # Retrieve S3 information from event
    bucket_name = event['Records'][0]['s3']['bucket']['name']
    s3_file_name = event['Records'][0]['s3']['object']['key']
 
    # Retrieves objects (CSV files) and retrieves data line by line
    resp=s3_client.get_object(Bucket=bucket_name, Key=s3_file_name)
    data=resp['Body'].read().decode("UTF-8")
    employees=data.split("\n")
 
    # Separate the values of the retrieved data one by one and register them in the table.
    for emp in employees:
        print(emp)
        emp_data=emp.split(",")
 
        try:
            table.put_item(
                Item = {
                    "Agent": emp_data[0],
                    "Agent Hierarchy Level Five": emp_data[1],
                    "Agent Hierarchy Level Four": emp_data[2],
                    "Agent Hierarchy Level Three": emp_data[3],
                    "Agent Hierarchy Level Two": emp_data[4],
                    "Agent Hierarchy Level One": emp_data[5],
                    "Duration": emp_data[6],
                    "Log out": emp_data[7],
                    "Log in": emp_data[8],
                    "Routing profile": emp_data[9],
                    "Last name": emp_data[10],
                    FFirst name :: emp_data[11]
                }
            )
        except Exception as:
            print(e)

aws amazon-s3 aws-lambda amazon-dynamodb

2022-09-30 16:17

1 Answers

Simply count the number of lines in progress and not register with if statements if you want to start.


2022-09-30 16:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.