Skip to content

Instantly share code, notes, and snippets.

@peacing
Last active November 17, 2020 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peacing/eb2607079973090c1a61b7103115bad6 to your computer and use it in GitHub Desktop.
Save peacing/eb2607079973090c1a61b7103115bad6 to your computer and use it in GitHub Desktop.
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