Run Folding@Home on AWS Spot Instances with CDK

24 October 2020 — Written by Eddy

Run Folding@Home with this AWS-CDK library on AWS and never forget to shut off expensive instances. With built-in TTL for your stack, you just define the lifetime of your EC2 instances and the stack will be deleted automatically.

About Folding@Home

Folding@home is a project focused on disease research. The problems F@H is solving require many computer calcul­ations – so you can donate your excess compute power to help their research. In that sense, you are part of a huge distributed supercomputer!

The architecture

The architecture follows this AWS blog post and leverages g4dn.xlarge Spot EC2 instances to maximise GPU vs price efficiency. Combined with a time to live mechanism you can launch your stack without having to worry about forgetting your running instances and waking up to a huge AWS bill.

Running at spot price drastically reduces the price from 0.59$ per hour to around 0.17$ in eu-west-1. That's a nice 70% in savings. spotpricing.png


After deployment, you can go into CloudWatch logs and open the log group fahlog. You can now see the progress every one of your instances makes towards the goal of unfolding proteins. wu01fahlog.png wu01 represents the work of the GPU and wu00 is the work of the CPU .

I hope you enjoy this library and together we can make a difference and help the Folding@Home program to succeed in their mission!

Big thanks to cdk-time-bomb for the TTL function and Ash Belmokadem and Vikin Shetty for debugging help!

How to deploy

  1. Create a new CDK app
cdk init app -l typescript
  1. Install CDK-Folding@Home in your CDK app
npm install cdkfoldingathome
  1. Open your stack.ts file in ./bin
  2. Import the cdkfoldingathome package
import * as folding from 'cdkfoldingathome';
  1. Create folding stack - important to specify accountId and region
const fah = new folding.FoldingathomeStack(app, 'folding', {
    timeToLive: cdk.Duration.hours(5),
    spotPrice: '0.40',
    numberOfInstances: 10,
    env: {
        account: "754786554548",
        region: "eu-west-1"
  1. Ready to build and deploy!
  2. Your stack gets destroyed once the TTL is up
  3. Double-check the first time to be sure your stack got really deleted 😉

I hope it all worked out for you and let me know if you have any ideas on how to improve CDK-Folding@home!

If you have any questions reach out on Github or Twitter.

© 2021 Built with ❤️