|
Voiced by Amazon Polly |
Conditional Writes: An Overview
Conditional writes, which verify an object’s existence before creating it, are now supported by Amazon S3. With this feature, you may more easily stop apps from overwriting any existing objects when you upload data. PutObject or CompleteMultipartUpload API calls can be used for conditional writes in directory and general-purpose buckets, in conjunction with the HTTP if-none-match conditional header to enable conditional writes.
Start Learning In-Demand Tech Skills with Expert-Led Training
- Industry-Authorized Curriculum
- Expert-led Training
Step 1 - Create S3 Bucket
Assuming you have an AWS user with permission to create s3 bucket and putObject permissions, also aws cli configured on your local machine or you can use aws cloudshell to perform the below operations:

Figure 1: create s3 bucket
To view the bucket goto s3 and type the name of the bucket you created:

Figure 2: view created s3 bucket
Step 2 - Upload an Object in S3
To upload an object with the key named HappyFace.jpg, take any file image file on your local machine, rename it to HappyFace.jpg, and upload the same using the below command.

Figure 3: Upload a object using s3 aws cli
To view the uploaded object get into your s3 bucket

Figure 4: view the uploaded object
Step 3 - Upload Object Again with Same Key and without Conditional Write
Now, when uploading object with the same key named HappyFace.jpg, it will overwrite the existing object

Figure 5: upload the object with same key

Figure 6: view the uploaded object overwritten existing object
We can see in the above image the time of the object when the “Last Modified” got updated, in Figure 6, as compared to object in Figure 5.
Step 4 - Upload the Object Again with Same Key and with Conditional Write
Now if we upload an object with the same key, with conditional write, the putObject operation will fail as the specified pre-condition does not hold, as object with already exists

Figure 7: Uploading the with object with Conditional Write
Step 5 - Delete the Created Resources
Delete the object HappyFace.jpg and remove the bucket.

Upskill Your Teams with Enterprise-Ready Tech Training Programs
- Team-wide Customizable Programs
- Measurable Business Outcomes
About CloudThat
WRITTEN BY Kamlesh N
Kamlesh Nenwani is a Subject Matter Expert at CloudThat, specializing in AWS Architecting and DevOps. With 13 years of experience in training and consultancy, he has guided over 2500+ professionals and students in mastering diverse technologies. Renowned for his clarity in explaining complex topics and his commitment to continuous learning, Kamlesh delivers practical, interactive sessions grounded in deep technical expertise.
Login

October 21, 2024
PREV
Comments