Skip to main content
This guide demonstrates how to set up a serverless ingest pipeline from an AWS S3 bucket into Mixpanel. Once this is set up, you can simply upload files containing events into the designated S3 bucket and the events will be ingested into Mixpanel, both one-time and on a recurring basis. Setup should take ~5-10 minutes.
image
Note: This guide assumes you are running in Amazon Web Services, and have the necessary IAM Access to have AWS Lambda read from S3.

Step 1: Create an S3 Bucket

Create a dedicated S3 bucket for this integration. We recommend including mixpanel-import in the name to make it explicit and avoid any accidental data sharing. You can create the bucket in any region, though it will need to be in the same region as your AWS Lambda function.

Step 2: Setup Import Config

Step 2a: Setup the Lambda Function

Create a new Lambda Function.
  • Select Author From Scratch.
  • Select a Python runtime.
  • Select Create Function.
image

Step 2b: Write the Lambda Function

Change the filename from lambda_function.py to main.py and edit the runtime settings handler to main.Handler. Paste the code below for main.py.
image
main.py

Step 2c: Add Trigger

Add a trigger so that your Lambda function runs whenever a new object is added to your bucket by selecting Add trigger under Function Overview. You will want to use the bucket created in Step 2 and select All object create events.
image

Step 2d: Update Configurations and Deploy

Select Configuration > General Configuration > Edit.
  • Change Memory to 1024 MB.
  • Change Timeout to 5 minutes.
image
Click Versions > Publish New Version to deploy the function. At this point, any file you upload to the bucket will trigger an invocation of the function and an import into Mixpanel. Let’s test it out!

Step 3: Test with sample data and watch the logs

Let’s test the connection with some sample events. Run the following to copy them to your bucket, which will trigger the import: gsutil cp cp gs://mixpanel-sample-data/10-events.json s3://your-s3-bucket/example.json Monitor the logs of your Lambda Function; you should see an Import Complete log line within a minute.
image
If you navigate to CloudWatch logs, you will see a more detailed log that includes the filename being imported and the first error encountered (if any).
image
Finally, let’s confirm that the events made it into Mixpanel. Head to the Events page, pick test_event in the event picker, and you should see the events you just imported.
image

Step 4: Import more data

We’re now ready for an import of your own data. If your data is not already in the Mixpanel format, this is a good time to write a transformation step to run as part of the Lambda. We recommend testing locally as you iterate on your data transformation logic, as it’s much quicker than redeploying the Lambda. The Overview page has sample code and data to test locally. Once you’re ready and have tested with a few small files, you can upload all the files for your import to your S3 bucket, and the import will kick off. This pipeline can be made recurring by uploading files to the S3 bucket periodically. We recommend partitioning files in S3 to ~200MB of JSON for optimal performance.