jweinst1
4/5/2018 - 8:23 PM

lambda handler function that writes small file to s3 bucket

lambda handler function that writes small file to s3 bucket

import json

import boto3

# Writes small file to an s3 bucket
def lambda_handler(event, context):
    s3 = boto3.client('s3')
    sample_file = open('/tmp/food.txt', 'w')
    jobid = event['queryStringParameters']['JobId']
    sample_file.write(jobid)
    sample_file.close()
    bucket_name = 'josh-lambda-test'
    s3.upload_file('/tmp/food.txt', bucket_name, '/tmp/food.txt')
    return {
       "isBase64Encoded": True,
       "statusCode": 200,
       "headers": { "headerName": "headerValue"},
       "body": json.dumps({'action':'wrote file containing %s to s3 bucket' % jobid})
    }