What follows is a description of my (Mark) first successful attempt at building and running JEDI on an AWS EC2 instance.  It's certainly not the only way and maybe not even the best way, but it's a starting point and I know it works.  This may also be of use to install other applications.

To build JEDI outside the container, take a look at Jim's instructions for a Linux PC

I'm sure there are better ways to do some of this, particularly with the security groups.  But again, this is just intended as a starting point to get the ball rolling.

Step 1: Create an Elastic File System (EFS)

In my first attempts to builld JEDI, I was getting memory problems.  The compilation halted at about 67% of the way through and then ran out of virtual memory.  I first tried launching my EC2 instance with more memory.  The default is 8 GiB but you can ask for up to 30 GiB in the free tier.   If you want to pay for it, that is beyond the free tier, you can ask for up to 16 TiB.  

However, a better option is to set up an Elastic file System (EFS).  Once you set this up, you can connect to this from multiple EC2 instances.  So, you could in principle build the code once and then just run the executable on as many EC2 instances as you wish.  So, it is a good home for your local copies of the JEDI repos as well as the binaries.  The EFS will grab more memory as needed to accommodate whatever you put in it.

So, to set up an EFS file system you can follow the instructions in this tutorial: 

https://aws.amazon.com/getting-started/tutorials/create-network-file-system/?trk=gs_card

In short, it involves going to your AWS console and navigating to Storage - EFS.  Select Create File System and then just go through the menus and select the default values for everything.  Make sure the VPC in particular is the default VPC (unless you deliberately want to use something else).   After you get through all the menus, you'll see a button on the lower right called Create File System.

To see information on your file system at any time, go to the main EFS dashboard, select File systems from the left menu, and select the file system you want.

Step 2: Launch an EC2 instance

You've probably already done this.  If not, there's another tutorial here:

https://aws.amazon.com/getting-started/tutorials/launch-a-virtual-machine/?trk=gs_card

But there are some specific things to keep in mind for JEDI. 

FIrst, choose this option for the operating system

Ubuntu Server 16.04 LTS (HVM), SSD Volume Type - ami-ba602bc2

I first tried the Amazon Linux 2 file system but I was not able to find the libarchive-dev package for the Amazon Linux AMIs - for a list of available packages, see: 

https://aws.amazon.com/amazon-linux-ami/2016.03-packages/

The libarchive-dev package is needed to install Singularity.  In the future I will look into how to build JEDI on an Amazon Linux AMI outside of the Singularity container but for the purpose of this document we can stick to Singularity on ubuntu.

The t2.micro resource works fine - go ahead and select that.

You may wish to go to Edit Security Groups and select an existing group if you have one to use.  Otherwise, AWS will generate one called, for example, launch-wizard-1.  

Then select an ssh key pair (to import your own see Importing an ssh key pair) and View Instances to see a list of your active instances.

Then - this is important - select your instance in the list and, from the menu, select Actions - Networking - change security group 

Select the default group in addition to the group that has already been assigned (launch-wizard-x).

Wait for the initialization to complete and then go to a terminal on your computer and ssh into your EC2 instance.  Note that the user name for an ubuntu instance is ubuntu.  So, if you have an imported ssh key set up, then it will look something like this:

ssh ubuntu@52.36.147.xxx


Step 3: Set up your Environment

Run these commands to set up your environment and install Singularity (we will soon automate these in a shell script but for now you can enter them manually - or copy and paste)

sudo apt-get install make
sudo apt-get install python
sudo apt-get install automake
sudo apt-get update
sudo apt-get install libtool
sudo apt-get install libarchive-dev
git clone https://github.com/singularityware/singularity.git
cd singularity
git checkout release-2.6
./autogen.sh
./configure --prefix=/usr/local
make
sudo make install
cd
singularity pull shub://JCSDA/singularity
git config --global credential.helper 'cache --timeout=3600'


Step 4: Mount EFS

First install nfs and create a directory to mount:

sudo apt-get install nfs-common
mkdir efs
sudo chmod a+rwx efs

Now go back to your web browser and navigate to the EFS dashboard.  Select the file system that you want to mount from the list.  You'll see a bunch of information about the file system.  Included in that information is a link that says:

Amazon EC2 mount instructions.

Select that and scroll down to the item called Using the NFS client.  Copy the command there and paste it into the command line of your EC2 ssh session.  It should look something like this:

sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-xxxxxxxx.efs.us-west-2.amazonaws.com:/ efs

Then you can close the EC2 mount instructions window.

Step 5: Enter Singularity Container, Build, and Run JEDI

Next enter the singularity container, create directories, and clone ufo-bundle.

Important: Make sure you do this in your efs directory!

singularity shell -e JCSDA-singularity-master-latest.simg
cd efs
mkdir src build
cd src
git clone https://github.com/JCSDA/ufo-bundle.git
cd ufo-bundle

Now edit the CMakeLists.txt file.  I usually comment out the compiles of eckit and fckit because they are already included in the container.  You can also turn off the doxygen build to speed up the compilation and use a bit less memory.  Next go to the build directory, compile, and run as usual:

cd ../../build
export FC=mpif90
ecbuild ../src/ufo-bundle
make
ctest

Note - I was previously using make -j4 here but I just tried that again and it hanged.  That could have been the source of my memory problems all along.  It seems to be happier if you omit the -j4.  So, it's possible that you can get it to work even without EFS (I did not try).  Still, I know the above works - I have reproduced it several times.

Let me know if you have any problems or questions with this - or, let me know if you have ideas on how to do this better.



  • No labels