簡體   English   中英

AWS Step Functions - 將列表傳遞給 Glue 的參數

[英]AWS Step Functions - pass list into Glue's argument

在我的工作流程中,我在 DynamoDB 中查詢load_fail狀態等於1的表。

如果至少有一個表,則 Glue 作業需要以該表列表作為--source_tables參數開始。

下面是我的整個 state 機器。

{
  "Comment": "A description of my state machine",
  "StartAt": "Query",
  "States": {
    "Query": {
      "Type": "Task",
      "Next": "Choice",
      "Parameters": {
        "TableName": "source_tables_load_status",
        "KeyConditionExpression": "load_fail = :load_fail",
        "ExpressionAttributeValues": {
          ":load_fail": {
            "S": "1"
          }
        }
      },
      "Resource": "arn:aws:states:::aws-sdk:dynamodb:query",
      "ResultSelector": {
        "count.$": "$.Count",
        "startTime.$": "$$.Execution.StartTime",
        "items.$": "$.Items[*].table_name.S"
      }
    },
    "Choice": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.count",
          "NumericGreaterThanEquals": 1,
          "Next": "start_glue"
        }
      ],
      "Default": "Success"
    },
    "start_glue": {
      "Type": "Task",
      "Resource": "arn:aws:states:::glue:startJobRun",
      "Parameters": {
        "JobName": "data-moving-glue",
        "Arguments": {
          "--dynamodb_metadata_table": "metadata_table",
          "--source_tables.$": "$.items"
        }
      },
      "End": true
    },
    "Success": {
      "Type": "Succeed"
    }
  }
}

目前我收到由"--source_tables.$": "$.items"引起的錯誤。

問題是如何使 state 機器工作的"--source_tables":["dbo.Table_Two", "dbo.Table_Three"]工作:

An error occurred while executing the state 'start_glue' (entered at the event id #9). 
The Parameters '{"JobName":"data-moving-glue","Arguments":{"--dynamodb_metadata_table":"metadata_table","--source_tables":["dbo.Table_Two", "dbo.Table_Three"]}}' 
could not be used to start the Task: [The value for the field '--source_tables' must be a STRING]

我用引號將結果關閉,使用States.Format將其轉換為字符串

https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-intrinsic-functions.html

"--source_tables.$": "States.Format('{}', $.items)"

新 output 是:

"--source_tables": "[\"dbo.TableOne\",\"dbo.TableTwo\"]"

另一方面,這可以通過 function 來處理。

eval僅用作示例 不要使用它,因為它可能會損害您的代碼

lst = "[\"dbo.TableOne\",\"dbo.TableTwo\"]"

for t in (eval(lst)): 
    print(t)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM