最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

amazon sqs - Argo workflow input parameters with value from SQS payload - Stack Overflow

matteradmin9PV0评论

I want to trigger an Argo workflow by reading value from SQS event source's payload. For example, my workflow template accepts an input parameter "date". I need to listen to AWS SQS and extract this value from my sqs payload and then trigger workflow by passing this value as input parameter.

Sample sqs payload: {"date" : "2024-01-01"}.

I am able to create workflow with input parameter & sqs event source, but I am missing the part where I need to extract the value of date from my incoming message and pass it on to workflow's parameter.

In below code, I need to pass the value from my dependency 'dependency-abc's payload which is {"date":"2024-01-01"} to 'input.parameters.date'

apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
  name: aws-sqs
spec:
  template:
    serviceAccountName: daadi-argo-sa
  dependencies:
    - name: dependency-abc
      eventSourceName: aws-sqs
      eventName: event-abc
  triggers:
    - template:
        name: sqs-workflow
        k8s:
          operation: create
          source:
            resource:
              apiVersion: argoproj.io/v1alpha1
              kind: Workflow
              metadata:
                generateName: aws-sqs-workflow-
              spec:
                serviceAccountName: argo-sa
                entrypoint: whalesay
                arguments:
                  parameters:
                  - name: date
                templates:
                - name: whalesay
                  inputs:
                    parameters:
                    - name: message
                  container:
                    image: docker/whalesay:latest
                    command: [cowsay]
                    args: ["{{inputs.parameters.date}}"]
        

I want to trigger an Argo workflow by reading value from SQS event source's payload. For example, my workflow template accepts an input parameter "date". I need to listen to AWS SQS and extract this value from my sqs payload and then trigger workflow by passing this value as input parameter.

Sample sqs payload: {"date" : "2024-01-01"}.

I am able to create workflow with input parameter & sqs event source, but I am missing the part where I need to extract the value of date from my incoming message and pass it on to workflow's parameter.

In below code, I need to pass the value from my dependency 'dependency-abc's payload which is {"date":"2024-01-01"} to 'input.parameters.date'

apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
  name: aws-sqs
spec:
  template:
    serviceAccountName: daadi-argo-sa
  dependencies:
    - name: dependency-abc
      eventSourceName: aws-sqs
      eventName: event-abc
  triggers:
    - template:
        name: sqs-workflow
        k8s:
          operation: create
          source:
            resource:
              apiVersion: argoproj.io/v1alpha1
              kind: Workflow
              metadata:
                generateName: aws-sqs-workflow-
              spec:
                serviceAccountName: argo-sa
                entrypoint: whalesay
                arguments:
                  parameters:
                  - name: date
                templates:
                - name: whalesay
                  inputs:
                    parameters:
                    - name: message
                  container:
                    image: docker/whalesay:latest
                    command: [cowsay]
                    args: ["{{inputs.parameters.date}}"]
        
Share Improve this question asked Nov 15, 2024 at 21:59 user28306650user28306650 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

The parameters, src, dependencyName, dataKey and dest need to be specified within k8s. These source and destination parameters map the dependency payload to the workflow parameters.

k8s:
  operation: create
  source:
    resource:
      apiVersion: argoproj.io/v1alpha1
      kind: Workflow
      metadata:
        generateName: aws-sqs-workflow-
      spec:
        serviceAccountName: argo-sa
        entrypoint: whalesay
        arguments:
          parameters:
            - name: date
        templates:
          - name: whalesay
            inputs:
              parameters:
                - name: message
            container:
              image: docker/whalesay:latest
              command: [cowsay]
              args: ["{{inputs.parameters.date}}"]
  parameters: # Parameters to pass to the Workflow
    - src: # Source of the data
        dependencyName: dependency-abc # Event source dependency
        dataKey: date # Selector for payload data (date)
      dest: spec.arguments.parameters.0.value # Destination for data selection (first parameter - date)

References:

  • https://github/argoproj/argo-events/blob/master/examples/sensors/aws-sqs.yaml
  • https://argoproj.github.io/argo-events/APIs/#argoproj.io/v1alpha1.StandardK8STrigger
  • https://argoproj.github.io/argo-events/
Post a comment

comment list (0)

  1. No comments so far