Skip to content
AWS Lambda example that uses ObsPy to decimate data from the SCEDC Public Data Set and store the output in S3
Python Shell Dockerfile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

The scedc-lambda project is an example Lambda function that uses ObsPy to decimate seismograms from the SCEDC Open Data Set by a factor of four and writes the output to another S3 bucket in the user's own account.


  • Your own AWS account
  • Docker
  • Python 3
  • boto3 module for Python
  • awscli module for Python

AWS Setup

In your AWS account:

  1. Create a new IAM role that has full S3 and Lambda permissions.

  2. Create two S3 buckets in the US-West-2 region. One of these buckets will hold the zip file for the Lambda function, and the other will hold the decimated data.

On your computer make sure you have AWS programmatic access keys that have full Lambda permissions.

Creating the Lambda Function

  1. Run this command: docker build -t lambda-env . to create a Docker image called lambda-env that runs amazonlinux:2018.03 and has Python 3.7 installed.

  2. Run this command: docker run -v $(pwd):/outputs lambda-env /bin/bash /outputs/ to create a zip file named The script installs numpy and Obspy in a virtual environment in a Docker container and zips the virtual environment along with, which contains the lambda function.

  3. Update with the names of your AWS profile in .aws/credentials, the name of your IAM role, the name you want to use for your lambda function, and the S3 buckets you created. You do not need to change INPUT_BUCKET or AWS_REGION if you're using the SCEDC Open Data Set. NCORES should be set to the number of CPU cores you want to use on your computer when calling the lambda function.

  4. Upload to the S3 bucket defined in LAMBDA_BUCKET in aws s3 cp s3://my-lambda-env-bucket/

  5. Run: python to create the Lambda function.

  6. Run: python to call the lambda function on one seismogram. You should see the decimated file appear in your output S3 bucket as decimated/2016/2016_123/

Running Decimation will call the Lambda function on a list of seismograms by key. Set the values of NCORES in to how many local CPU cores you want to use for sending Lambda function calls, and run: python filename_of_seismogram_list

The list should contain the full path of each seismogram, one per line. Below is a sample listing:

2016/2016_001/ 2016/2016_001/ 2016/2016_001/ 2016/2016_001/

You can generate listings by using the "aws s3 ls" command.

Updating the Lambda Function

If you need to modify the Lambda function, make your changes in and replace in the zip file by running: zip -r This only replaces, so you don't need to re-run the docker command to create a new zip file.

Then run: python which will automatically upload the new version of and reload the Lambda function.

You can’t perform that action at this time.