How to concatenate character strings in step function for AWS Glue parameters?

0

HI All,

I have a step function to call an AWS Glue job with below step definition:

    "glue-redshift-call": {
      "Type": "Task",
      "Resource": "arn:aws:states:::glue:startJobRun.sync",
      "Parameters": {
        "JobName": "GlueJobRedshiftStoredProcCa-meJ8P3QMSC5p",
        "Arguments": {
          "--SQLStatement": "call dw_merge_vendor('TNG', 'ASENTINEL')"
        }
      },
      "Next": "post-processing"
    },

As shown above, SQLStatement parameter is hardcoded as call dw_merge_vendor('TNG', 'ASENTINEL') in this. But I need to make it dynamic, parameter based. As mentioned in Step Function new features Blogpost, I tried below syntax to make it dynamic, but it's not working. Would you be able to suggest the correct syntax if I am doing something wrong here?

"Arguments": {
  "--SQLStatement": "States.Format('call dw_merge_vendor('{}', '{}'),  ', $.param1, $.param2)"
}
AWS
asked 4 years ago3524 views
1 Answer
0
Accepted Answer

There are two issues with what you did. The first is that when you reference other variables or intrinsic functions, you need to append .$ to the key. The second is that when you need to include ' in the string, you need to escape them using \\. It should look like this:

"Arguments": {
"--SQLStatement.$": "States.Format('call dw_merge_vendor({}, {}),', $.param1, $.param2)"
}

If you need the params enclosed in ', you should use the following:

"Arguments": {
"--SQLStatement.$": "States.Format('call dw_merge_vendor(\\'{}\\', \\'{}\\'),', $.param1, $.param2)"
}
profile pictureAWS
EXPERT
Uri
answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions