Using Wait Conditions For an Object

You can use wait commands to pause your script execution until a specific condition is met for your object. This is particularly useful for automated workflows, where you need to ensure that a certain state is reached before proceeding with the next execution.

If you need to retrieve metadata about a specific object, see Getting Information About the Metadata of an Object.

Using Wait Conditions For an Object Using AWS CLI (s3api)

Before you begin: Install and configure AWS CLI. For more information, see Installing and Configuring AWS CLI.

Wait Until an Object Exists

To ensure that an object exists and is accessible before performing further actions, use the wait object-exists command following this syntax:

Request sample
$ aws s3api wait object-exists \
    --profile YOUR_PROFILE \
    --bucket BUCKET \
    --if-match "\"12345a6b76656da1b64f287c8627af7\"" \
    --if-modified-since "2024-01-10" \
    --if-none-match "\"12345a6b76656da1b64f287c8627af7\"" \
    --if-unmodified-since "2024-01-10" \
    --key OBJECT \
    --version-id qAfAAsAAuA00kclkg0A0AAuAAjaAtA. \
    --part-number "1" \
    --endpoint https://oos.eu-west-2.outscale.com

This command contains the following attributes that you need to specify:

  • (optional) profile: The named profile you want to use, created when configuring AWS CLI. For more information, see Installing and Configuring AWS CLI.

  • bucket: The name of the bucket containing the object you want to verify the existence of.

  • (optional) if-match: Requests the object only if its ETag matches the ETag you specify for this attribute.

  • (optional) if-modified-since: Requests the object only if it has been modified after the date (in ISO 8601 format) you specify for this attribute.

  • (optional) if-none-match: Requests the object only if its ETag does not match the ETag you specify for this attribute.

  • (optional) if-unmodified-since: Request the object only if it has not been modified since the date (in ISO 8601 format) you specify for this attribute.

    If the different conditions are not met, the command will return various errors: error 412: precondition failed for if-match and if-unmodified-since, and error 304: not modified for if-modified-since and if-none-match.

  • key: The name of the object you want to verify the existence of.

  • (optional) version-id: The ID of the version of the object you want to verify existence of. For more information, see Using Bucket Versioning.

    If the version-id starts with a hyphen (-), you need to specify the attribute following this syntax:

    --version-id=-qAfAAsAAuA00kclkg0A0AAuAAjaAtA.
  • (optional) part-number: The part number of the object being read (between 1 and 10000, both included). For more information, see Using Multipart Upload.

  • endpoint: The endpoint corresponding to the Region you want to send the request to. For more information, see Installing and Configuring AWS CLI.

The command polls the bucket every 5 seconds until a successful state is reached, after which the command should return no output.

However, after 20 successive failed checks (100 seconds in total), the command returns the following error message:

Result sample
Waiter ObjectExists failed: Max attempts exceeded. Previously accepted state: Matched expected HTTP status code: 404

Wait Until an Object No Longer Exists

To ensure that an object no longer exists before performing further actions, use the wait bucket-not-exists command following this syntax:

Request sample
$ aws s3api wait object-not-exists \
    --profile YOUR_PROFILE \
    --bucket BUCKET \
    --if-match "\"12345a6b76656da1b64f287c8627af7\"" \
    --if-modified-since "2024-01-10" \
    --if-none-match "\"12345a6b76656da1b64f287c8627af7\"" \
    --if-unmodified-since "2024-01-10" \
    --key OBJECT \
    --version-id qAfAAsAAuA00kclkg0A0AAuAAjaAtA. \
    --part-number "1" \
    --endpoint https://oos.eu-west-2.outscale.com
  • (optional) profile: The named profile you want to use, created when configuring AWS CLI. For more information, see Installing and Configuring AWS CLI.

  • bucket: The name of the bucket containing the object you want to wait for until it no longer exists.

  • (optional) if-match: Requests the object only if its ETag matches the ETag you specify for this attribute.

  • (optional) if-modified-since: Requests the object only if it has been modified after the date (in ISO 8601 format) you specify for this attribute.

  • (optional) if-none-match: Requests the object only if its ETag does not match the ETag you specify for this attribute.

  • (optional) if-unmodified-since: Request the object only if it has not been modified since the date (in ISO 8601 format) you specify for this attribute.

  • key: The name of the object you want to wait for until it no longer exists.

  • (optional) version-id: The ID of the version of the object you want to verify existence of. For more information, see Using Bucket Versioning.

    If the version-id starts with a hyphen (-), you need to specify the attribute following this syntax:

    --version-id=-qAfAAsAAuA00kclkg0A0AAuAAjaAtA.
  • (optional) part-number: The part number of the upload (between 1 and 10000, both included). For more information, see Using Multipart Upload.

  • endpoint: The endpoint corresponding to the Region you want to send the request to. For more information, see Installing and Configuring AWS CLI.

The command polls the bucket every 5 seconds until a successful state is reached, after which the command should return no output.

However, after 20 successive failed checks (100 seconds in total), the command returns the following error message:

Result sample
Waiter ObjectNotExists failed: Max attempts exceeded.

Related Pages

AWS™ and Amazon Web Services™ are trademarks of Amazon Technologies, Inc or its affiliates in the United States and/or other countries.