CSNSE / subs5

0 stars 0 forks source link

Next Steps in Lambda #19

Closed AmazingAJ10 closed 5 months ago

AmazingAJ10 commented 6 months ago

Created a new policy, attached it to a new role, attached the new role to a new log group, which was attached to the new lambda function. I also set all of the required permissions. Tested the new lambda function and now I am working on uploading objects to the S3 bucket connected to the function, which I am building an S3 trigger for.

AmazingAJ10 commented 6 months ago

Created a lambda trigger and connected it to the CloudWatch where I can see the uploads and logs. I am currently working on changing the configuration of the test code in the lambda function, but I need to get the correct records to show up in the CloudWatch because I am not getting the same results in my log events as the person in the tutorial.

AmazingAJ10 commented 6 months ago

Continue with tutorial... found records in CloudWatch, put them into the test configuration in lambda and adding other tools to lambda for csv reading functionality.

AmazingAJ10 commented 5 months ago

Now calling a CSV into the lambda... for some reason where the tutorial grabs the name of the file, mine is grabbing the name of the bocket, think it has to do with the configuration of the test event... this is my next think to work on

AmazingAJ10 commented 5 months ago

Going well, I successfully got the lambda to read the csv and display it in a table, next is to mainpulate it, grab what I want, and start doing some machine learning.

Lambda Code from today:

import json import boto3 s3_client = boto3.client('s3') dynamodb = boto3.resource('dynamodb') table = dynamodb.Table('user') def lambda_handler(event, context): bucket = event['Records'][0]['s3']['bucket']['name'] csv_file_name = event['Records'][0]['s3']['object']['key'] csv_object = s3_client.get_object(Bucket=bucket,Key=csv_file_name) print(type(csv_object)) file_reader = csv_object['Body'].read().decode("utf-8") print(type(file_reader)) print(file_reader) users = file_reader.split("\n") print(users) users = list(filter(None,users)) print(users) for user in users: user_data = user.split(",") table.put_item(Item = { "id" : user_data[0] // Add the rest of what features I want })

return "success"