Last active
November 17, 2020 12:58
-
-
Save peacing/eb2607079973090c1a61b7103115bad6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import awswrangler as wr | |
ipmort boto3 | |
dynamo = boto3.resource('dynamodb') | |
table = dynamo.Table('data-services-dev-testing') | |
sqs = boto3.client('sqs') | |
def lambda_handler(event, context): | |
for record in event['Records']: | |
filepaths = record['body'].split(',') | |
filepath = filepaths.pop() | |
#let's you read s3 files directly into memory w/o downloading | |
df = wr.pandas.read_parquet(path=filepath).astype(str) | |
with table.batch_writer() as bw: | |
for record in df.to_dict("records"): | |
bw.put_item(Item=record) | |
# create new SQS message if still files to process | |
if len(filepaths) > 0: | |
new_message = ','.join(file_names) | |
sqs.send_message(QueueUrl='url_of_queue', MessageBody=new_message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment