Set the timeout to at least 1 minute , as fetching and processing data can take time.
Ensure your Lambda has s3:PutObject permissions if you want to save the file to Amazon S3 .
To create this automation, you will typically use with the pandas and openpyxl libraries. 1. Prepare Your Environment Download EARTHQUAKE MAGNIDUTE DATA with lambda (1) xlsx
import json import pandas as pd import requests import boto3 from io import BytesIO def lambda_handler(event, context): # 1. Fetch data from USGS API (GeoJSON format) url = "https://usgs.gov" response = requests.get(url) data = response.json() # 2. Extract relevant magnitude and location details features = data['features'] quakes = [] for f in features: prop = f['properties'] quakes.append({ 'Magnitude': prop['mag'], 'Place': prop['place'], 'Time': pd.to_datetime(prop['time'], unit='ms'), 'Type': prop['type'] }) # 3. Convert to Excel using Pandas df = pd.DataFrame(quakes) excel_buffer = BytesIO() with pd.ExcelWriter(excel_buffer, engine='openpyxl') as writer: df.to_excel(writer, index=False, sheet_name='Earthquakes') # 4. Upload to S3 (optional, for storage) s3 = boto3.client('s3') bucket_name = "your-bucket-name" s3.put_object(Bucket=bucket_name, Key="earthquakes.xlsx", Body=excel_buffer.getvalue()) return { 'statusCode': 200, 'body': "XLSX file successfully generated and stored." } Use code with caution.
Download the appropriate .whl files for your Python version (e.g., Python 3.9) from PyPI . Set the timeout to at least 1 minute
To download earthquake magnitude data as an .xlsx file using , you can automate the process of fetching data from the USGS Earthquake API and converting it into a spreadsheet. Quick Guide to Building the Lambda Function
Zip them into a folder structure: python/lib/python3.x/site-packages/ . Upload this zip as a new Layer in the AWS Lambda Console . Extract relevant magnitude and location details features =
If you don't need automation, you can download pre-filtered data directly from the USGS Earthquake Catalog in , which opens natively in Excel.