Ugly Green Logo

Container Registry

Download Website

GitHub Organization

Slack Workspace

April 05, 2024

Do NOT forget the AWS Amplify Logs

by John Lukach

I recently needed AWS Amplify logs for an investigation that became a painful experience; thus, I recommend adding an AWS Lambda that exports access logs daily with the provided Python example.

Log File Format

Python Libraries

import boto3
import datetime
import gzip
import os
import requests

Previous Day

yesterday = - datetime.timedelta(days=1)

Generate Access Logs

    client = boto3.client('amplify', region_name = 'us-east-2')

    response = client.generate_access_logs(
        startTime = datetime.datetime(yesterday.year, yesterday.month,,
        endTime = datetime.datetime(yesterday.year, yesterday.month,,
        domainName = '',
        appId = os.environ['APP_ID']

Download Access Logs

d = requests.get(response['logUrl'])

Set Filename

fname = str(yesterday.year)+'-'+str(yesterday.month)+'-'+str('-4n6ircom.csv'

Write Access Logs

    if d.status_code == 200:
        with open('/tmp/'+fname, 'wb') as f:

Compress Access Logs

    with open('/tmp/'+fname, 'rb') as f_in:
        with'/tmp/'+fname+'.gz', 'wb') as f_out:

Archive Access Logs

    s3 = boto3.client('s3')

tags: aws - amplify - cloudfront - access - logs