Amazon S3 · Arazzo Workflow

Amazon S3 Get Object or Create It

Version 1.0.0

Check whether an object exists with HEAD and upload it only if missing.

1 workflow 1 source API 1 provider
View Spec View on GitHub ArchiveBackupCloud StorageData StorageObject StorageScalable StorageArazzoWorkflows

Provider

amazon-s3

Workflows

get-or-create-object
Upload an object only when it does not already exist.
Uses HeadObject to detect the presence of an object and only writes it with PutObject when the object is not found.
2 steps inputs: bucket, objectBody, objectKey outputs: createdEtag, existingEtag
1
headObject
HeadObject
Probe for the object with a HEAD request. A 200 means it exists; a 404 means it must be created.
2
putObject
PutObject
Upload the object's binary body because the HEAD request reported it was not present.

Source API Descriptions

Arazzo Workflow Specification

amazon-s3-get-or-create-object-workflow.yml Raw ↑
arazzo: 1.0.1
info:
  title: Amazon S3 Get Object or Create It
  summary: Check whether an object exists with HEAD and upload it only if missing.
  description: >-
    An idempotent write pattern for Amazon S3. The workflow probes for an object
    with a HEAD request and branches: when the object already exists it ends and
    reports the existing ETag, and when the object is missing it uploads the
    supplied body with a PUT. This avoids overwriting data that is already in
    place. Every step spells out its request inline so the flow can be read and
    executed without opening the underlying OpenAPI description.
  version: 1.0.0
sourceDescriptions:
- name: s3RestApi
  url: ../openapi/amazon-s3-rest-api-openapi.yml
  type: openapi
workflows:
- workflowId: get-or-create-object
  summary: Upload an object only when it does not already exist.
  description: >-
    Uses HeadObject to detect the presence of an object and only writes it with
    PutObject when the object is not found.
  inputs:
    type: object
    required:
    - bucket
    - objectKey
    - objectBody
    properties:
      bucket:
        type: string
        description: The bucket that holds (or will hold) the object.
      objectKey:
        type: string
        description: The key to check for and conditionally write.
      objectBody:
        type: string
        description: The raw object payload to upload when the object is missing.
  steps:
  - stepId: headObject
    description: >-
      Probe for the object with a HEAD request. A 200 means it exists; a 404
      means it must be created.
    operationId: HeadObject
    parameters:
    - name: Bucket
      in: path
      value: $inputs.bucket
    - name: Key+
      in: path
      value: $inputs.objectKey
    successCriteria:
    - condition: $statusCode == 200
    outputs:
      existingEtag: $response.header.ETag
    onSuccess:
    - name: alreadyExists
      type: end
      criteria:
      - condition: $statusCode == 200
    onFailure:
    - name: notFoundCreate
      type: goto
      stepId: putObject
      criteria:
      - condition: $statusCode == 404
  - stepId: putObject
    description: >-
      Upload the object's binary body because the HEAD request reported it was
      not present.
    operationId: PutObject
    parameters:
    - name: Bucket
      in: path
      value: $inputs.bucket
    - name: Key+
      in: path
      value: $inputs.objectKey
    requestBody:
      contentType: application/octet-stream
      payload: $inputs.objectBody
    successCriteria:
    - condition: $statusCode == 200
    outputs:
      createdEtag: $response.header.ETag
      versionId: $response.header.x-amz-version-id
  outputs:
    existingEtag: $steps.headObject.outputs.existingEtag
    createdEtag: $steps.putObject.outputs.createdEtag