diff --git a/samtools.wdl b/samtools.wdl
index 395c9acdc8a83efa426aeabf0ff67bb9b59119d1..dcec975146973383f36fa0f71ed99a971784a736 100644
--- a/samtools.wdl
+++ b/samtools.wdl
@@ -31,14 +31,21 @@ task BgzipAndIndex {
 task Index {
     input {
         File bamFile
+        String bamPath = basename(bamFile)
         String dockerImage = "quay.io/biocontainers/samtools:1.8--h46bd0b3_5"
     }
-    String bamPath = basename(bamFile)
     String bamIndexPath = sub(bamPath, "\.bam$", ".bai")
 
     command {
-        ln ~{bamFile} ~{bamPath}
+        bash -c '
+        set -e
+        # Make sure bamPath does not exist.
+        if [ ! -f ~{bamPath} ]
+        then
+            ln ~{bamFile} ~{bamPath}
+        fi
         samtools index ~{bamPath} ~{bamIndexPath}
+        '
     }
 
     output {