async function handler()

in lib/lambda/save-to-s3/index.ts [9:34]


async function handler(event: any): Promise<string | void> {
  try {

    console.log('Raw event', event);
    
    if (!event.detail.data) { // no need to store object upon delete
      return ''
    }

    const key = generateS3Key(event);
    const body = JSON.stringify(event.detail.data);
    const params: PutObjectRequest = {
      Body: body,
      ContentType: 'application/json',
      Bucket: bucket, 
      Key: key
     };
    const s3 = new AWS.S3({apiVersion: '2006-03-01'});
    await s3.putObject(params).promise();
    return key;

  } catch (e) {
    console.log('There has been an error while trying to save to Amazon S3', e);
    throw e;
  }
}