|
| 1 | + |
| 2 | +# @cumulus/aws-api-proxy-task |
| 3 | + |
| 4 | +This task provides a Cumulus Message Adapter (CMA) wrapped proxy that invokes a |
| 5 | +pre-approved AWS API action via boto3. It is intended for use within a Cumulus |
| 6 | +workflow and enforces guardrails through schema validation and IAM permissions. |
| 7 | +Currently, the schema allows the SNS `publish` action, with support for multiple |
| 8 | +invocations in a single task execution via `iterate_by`. |
| 9 | + |
| 10 | +## Usage |
| 11 | + |
| 12 | +This lambda takes the following input and config objects, derived from workflow |
| 13 | +configuration using the |
| 14 | +[Cumulus Message Adapter](https://github.com/nasa/cumulus-message-adapter/blob/master/CONTRACT.md). |
| 15 | +The output from the task follows the CMA contract and provides the information |
| 16 | +detailed below. |
| 17 | + |
| 18 | +### Configuration |
| 19 | + |
| 20 | +| field name | type | default | required | values | description |
| 21 | +| ---------- | ---- | ------- | -------- | ------ | ----------- |
| 22 | +| service | string | N/A | yes | `sns` | AWS service to invoke |
| 23 | +| action | string | N/A | yes | `publish` | Service action to invoke |
| 24 | +| parameters | object | N/A | yes | N/A | Parameters passed to the AWS SDK action |
| 25 | +| parameters.TopicArn | string | N/A | yes | N/A | SNS Topic ARN to publish to |
| 26 | +| parameters.Message | string | N/A | yes | N/A | Message string to publish |
| 27 | +| iterate_by | string | N/A | no | N/A | Name of a `parameters` field containing a list; each value produces a separate call |
| 28 | +| parameter_filters | array | [] | no | N/A | List of transformations to apply to parameter fields before invoking the API |
| 29 | +| parameter_filters[].name | string | N/A | yes | `json.dumps` | Filter to apply |
| 30 | +| parameter_filters[].field | string | N/A | yes | N/A | Parameter field name to transform |
| 31 | + |
| 32 | +The following sample configuration publishes two messages to two topics by |
| 33 | +iterating over a list of ARNs: |
| 34 | + |
| 35 | +```json |
| 36 | +{ |
| 37 | + "service": "sns", |
| 38 | + "action": "publish", |
| 39 | + "iterate_by": "TopicArn", |
| 40 | + "parameters": { |
| 41 | + "TopicArn": [ |
| 42 | + "arn:aws:sns:us-east-1:123456789012:ExampleTopicA", |
| 43 | + "arn:aws:sns:us-east-1:123456789012:ExampleTopicB" |
| 44 | + ], |
| 45 | + "Message": "Message for topic" |
| 46 | + } |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +When `iterate_by` is set, the named field in `parameters` must be a list. The |
| 51 | +task will create one API call per list entry by substituting each value into the |
| 52 | +specified field. If `parameter_filters` are provided, each filter is applied to |
| 53 | +the named field across all generated parameter sets. The only supported filter |
| 54 | +is `json.dumps`, which serializes the field value as JSON. |
| 55 | + |
| 56 | +### Input |
| 57 | + |
| 58 | +The input payload for this task is expected to be empty. All invocation details |
| 59 | +are passed via the task configuration. |
| 60 | + |
| 61 | +### Output |
| 62 | + |
| 63 | +The task returns a list of boto3 responses (one per entry generated by |
| 64 | +`iterate_by`). |
| 65 | +Each response includes the `MessageId` for the SNS publish request. Example: |
| 66 | + |
| 67 | +```json |
| 68 | +{ |
| 69 | + "result_list": [ |
| 70 | + { |
| 71 | + "MessageId": "11111111-1111-1111-1111-111111111111" |
| 72 | + }, |
| 73 | + { |
| 74 | + "MessageId": "22222222-2222-2222-2222-222222222222" |
| 75 | + } |
| 76 | + ] |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +### Example workflow configuration |
| 81 | + |
| 82 | +This task can be used to send workflow notifications via SNS in a controlled |
| 83 | +and audited way. A sample task state could look like: |
| 84 | + |
| 85 | +```json |
| 86 | +{ |
| 87 | + "Publish Workflow Notification": { |
| 88 | + "Type": "Task", |
| 89 | + "Resource": "${aws_api_proxy_arn}", |
| 90 | + "Parameters": { |
| 91 | + "cma": { |
| 92 | + "event.$": "$", |
| 93 | + "task_config": { |
| 94 | + "service": "sns", |
| 95 | + "action": "publish", |
| 96 | + "parameter_filters": [ |
| 97 | + { |
| 98 | + "name": "json.dumps", |
| 99 | + "field": "Message" |
| 100 | + } |
| 101 | + ], |
| 102 | + "parameters": { |
| 103 | + "TopicArn": "${sns_publish_arn}", |
| 104 | + "Message.$": "$.meta.cnm" |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + }, |
| 109 | + "ResultPath": null, |
| 110 | + "End": true |
| 111 | + } |
| 112 | +} |
| 113 | +``` |
| 114 | + |
| 115 | +## Architecture |
| 116 | + |
| 117 | +```mermaid |
| 118 | +graph TB |
| 119 | + A["AWS Lambda Handler<br/>lambda_handler"] -->|calls| B["Lambda Adapter<br/>lambda_adapter"] |
| 120 | + B -->|invokes boto3 client| C["AWS SDK (boto3)"] |
| 121 | + C -->|executes action| D["AWS Service API<br/>(e.g., SNS publish)"] |
| 122 | + D -->|responses| E["CMA Output<br/>result_list"] |
| 123 | +``` |
| 124 | + |
| 125 | +### Internal Dependencies |
| 126 | + |
| 127 | +This task relies on the Cumulus Message Adapter and requires an IAM role that |
| 128 | +permits the configured AWS service action (for example, `sns:Publish` to specific |
| 129 | +topics). Guardrails are enforced by schema validation and IAM permissions. |
| 130 | + |
| 131 | +### External Dependencies |
| 132 | + |
| 133 | + - boto3 |
| 134 | + - https://github.com/nasa/cumulus-message-adapter |
| 135 | + - https://github.com/nasa/cumulus-message-adapter-python |
| 136 | + |
| 137 | +## Contributing |
| 138 | + |
| 139 | +To make a contribution, please [see our Cumulus contributing guidelines](https://github.com/nasa/cumulus/blob/master/CONTRIBUTING.md) |
| 140 | +and our documentation on [adding a task](https://nasa.github.io/cumulus/docs/adding-a-task) |
| 141 | + |
| 142 | +## About Cumulus |
| 143 | + |
| 144 | +Cumulus is a cloud-based data ingest, archive, distribution and management |
| 145 | +prototype for NASA's future Earth science data streams. |
| 146 | + |
| 147 | +[Cumulus Documentation](https://nasa.github.io/cumulus) |
0 commit comments