<p>On my local machine I can do <code>mkdir</code> and trust that this operation is atomic. I can thus use it as a lock. Can I similarly use <code>mkdir</code> on an EC2 instance with EBS attached and have it be atomic? </p>

<p>For further context, I am thinking of a situation where I have multiple Kubernetes Pods running on a Kubernetes Node with one <code>persistentVolume</code> (AWS EBS) between them. If one of these pods is looking to get exclusive access to a folder in this volume, can it do so? The pods are sharing read-only data, but I to trigger an <code>aws s3 sync</code> only once per week, not once-per-pod-per-week. </p>

thundergolfer
<p>Since EBS is not a filesystem...</p>

<blockquote>
  <p>Amazon Elastic Block Store (Amazon EBS) provides block level storage volumes for use with EC2 instances.</p>
  
  <p><a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonEBS.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonEBS.html</a></p>
</blockquote>

<p>...there is no direct answer to the question, because it isn't the correct question.  EBS -- as a block device -- is not responsible for or even aware of the actual filesystem operations or its guarantees.</p>

<p>tl;dr: If <code>mkdir()</code> is atomic in the filesystem you are using, then it will still be atomic if that filesystem is on an EBS volume.</p>

<p>Whether using <code>mkdir()</code> for locking is a good practice is a <a href="https://stackoverflow.com/q/7208447/1695906">different question</a>.</p>
