Alternera.Plugins.Sqs (alternera_plugin_sqs v0.9.0)

Copy Markdown View Source

Sends to and receives from Amazon SQS queues, or any service that speaks SQS's JSON protocol (ElasticMQ, LocalStack). One step does one operation:

  • send sends one message to the queue: its body is the step's source (the side's body by default), with attributes (String message attributes), and, for a FIFO queue, message_group_id and deduplication_id, or delay_seconds;

  • receive long-polls the queue for up to max_messages messages, waiting up to wait_time_s for the first, and hides each from other consumers for the queue's visibility timeout, or visibility_timeout_s. Its outputs are the messages (messages, message the first, count). A poll that brings none ends the pipeline with nothing (when_empty: "return", the default), which a trigger's run counts as empty, or goes on with no messages ("continue"). With delete: "immediate" the messages are deleted as they arrive (at most once); the default, "manual", leaves that to later steps;

  • delete deletes one received message by its receipt_handle;

  • release makes a received message visible again after visibility_timeout_s (default 0: at once), so the queue delivers it again;

  • counts reads the queue's approximate counts: the messages waiting (waiting), received and not yet deleted (in_flight) and delayed (delayed).

    %{"operation" => "receive", "queue_url" => "https://sqs.eu-north-1.amazonaws.com/123456789012/orders", "access_key_id" => "{{AWS_ACCESS_KEY_ID}}", "secret_access_key" => "{{secret.AWS_SECRET_ACCESS_KEY}}", "proxy_user_id" => "0192…", "max_messages" => 5}

A queue is consumed by a source trigger (Pipelines.Trigger, mode message) whose source is this plugin's (source/0, Sqs.Source): the proxy polls the queue, runs the pipeline once per message and deletes or releases each one by how its run ended. A receive step in a pipeline a continuous trigger runs, with a For each that deletes each message (${input.item.receipt_handle}), does the same by hand.

The calls

Every call is a POST to the queue URL's origin with the queue URL in its JSON body (AmazonSQS.<Action> in X-Amz-Target), signed with AWS Signature Version 4 (Sqs.SigV4) for the service sqs in region (taken from an AWS queue URL's host when left out). It goes to the forward side as the proxy user proxy_user_id names (Plugin.Provisional.Outbound), as a Request step's does, and is recorded as an exchange of its own under the step's, its Authorization redacted.

access_key_id is a plain template, so a tenant variable fills it; secret_access_key is one tenant secret reference, {{secret.AWS_SECRET_ACCESS_KEY}}, revealed in-process to sign the call (Plugin.Secret.reveal/3) and never sent. Both and region may be set by a Configuration step (configurable). queue_url, the receipt handle, the FIFO ids and the attributes' values are plain templates: each goes into a message the queue keeps and hands to its consumers.

Results

A status outside 2xx fails http_status, with the status, SQS's error code and its message; an immediate delete SQS refuses for a message fails sqs_failure; an answer that is not the JSON it should be fails invalid_response. A failed call keeps the outbound call's type (connection, timeout, tls, …).

A message is %{"message_id", "receipt_handle", "body", "attributes", "system_attributes", "receive_count"}, plus "json" when its body parses as a JSON object or array.

In the preview

The step reaches outside (side_effect?/0): a preview sends nothing, reveals no secret and says what it would call, with the call's fingerprint; a played one runs for real and returns its record. In a request phase that runs provisionally it waits for the deciding pass.

Summary

Functions

A receive step's defaults, by key.

The longest access key id a step or a source takes, in bytes.

The settings keys operation takes beside the common ones.

The outputs a step of operation produces, a subset of outputs/0: a To row of another operation's output would write nothing, so init/1 refuses it, and the editor offers only these. An unknown operation has all of them.

The operations a step does.

The inclusive range of a number setting.

The queue as a message source, for a source trigger (Sqs.Source).

Functions

defaults()

@spec defaults() :: %{required(String.t()) => term()}

A receive step's defaults, by key.

max_access_key_id()

@spec max_access_key_id() :: pos_integer()

The longest access key id a step or a source takes, in bytes.

operation_keys(operation)

@spec operation_keys(String.t()) :: [String.t()]

The settings keys operation takes beside the common ones.

operation_outputs(operation)

@spec operation_outputs(String.t() | nil) :: [Alternera.Plugin.output()]

The outputs a step of operation produces, a subset of outputs/0: a To row of another operation's output would write nothing, so init/1 refuses it, and the editor offers only these. An unknown operation has all of them.

operations()

@spec operations() :: [String.t()]

The operations a step does.

range(binary)

@spec range(String.t()) :: {integer(), integer()}

The inclusive range of a number setting.

source()

@spec source() :: module()

The queue as a message source, for a source trigger (Sqs.Source).