How do I pass arguments to a Glue job in CloudFormation YAML? - yaml

You can pass arguments to an AWS Glue job via the --arguments parameter (see here).
The CloudFormation documentation says DefaultArguments are "UTF-8 string–to–UTF-8 string key-value pairs" and that their type is "JSON object". Since YAML is a super set of JSON, I was expecting to be able to pass arguments like this in a (YAML) CloudFormation template:
DefaultArguments:
"--arguments": {"--test_argument": "foo"}
However, it raises this error during CloudFormation deployment:
Property validation failure: [Value of property {/DefaultArguments/--arguments=} does not match type {String}]
How do I specify the values correctly?

The correct way of passing multiple parameters is
DefaultArguments:
"--argument1": value1
"--argument2": value2
and then accessing them in the job (e.g. in Python) like this:
from awsglue.utils import getResolvedOptions
args = getResolvedOptions(sys.argv, ['argument1', 'argument2'])
print args['argument1']
print args['argument2']
What confused me was that for passing parameters with the AWS CLI, you use an explicit --arguments='--argument1="value1"' structure but in CloudFormation, you specify arguments one by one.

The value for the key --arguments needs to be a string, but you actually give it a mapping (or in JSON-speak an object), because it starts witha {. You should quote the value, and since you have double quotes in the value, you best do that with single quotes:
DefaultArguments:
"--arguments": '{"--test_argument": "foo"}'
(any existing single quotes in the value you would need to escape by putting two single quotes)
If your JSON is more complex it can be benificial to use folded-style scalars. Within those the { has no special meaning either and (single) newlines followed by spaces are replaced by a single space. So the following loads to same data as the solution above:
DefaultArguments:
"--arguments": >
{"--test_argument":
"foo"}
Of course with YAML (1.2) being a superset of JSON, glue could easily assume that a value is already parsed if it is not a string, but it doesn't seem to be that smart and always expects the JSON in string form.

Related

JMETER __P cannot digest the value

I have a variable that I use in my API's header.
It contains many special characters in that string so JMeter cannot digest the value.
'myCode' variable I plan to use in CLI (NON-GUI) mode so I need to be able to control it.
Sometimes I see also double or single quotes ('"' and "'")in the string so it can be a case that I need to deal with this
Any ideas on how to handle this?
${__P(myCode,0$M#3C3dKLo&1=9gIYP#CvC5.sWNvDD2mTWmn)=uoj}peA6W8?ry]s/Tn}J{C:Z%,J?M0+{&&ywi]3wM"1lG(&!q++88b1B>I2G1=+cso}trWmOSIo]INi^&%&^GYUFFsgdnJ.TsPTM[Jq+g2CWKvRZ495G0DqH>Yj%sUPqhj2aCmbWun)}
JMeter can "digest" the value, if you're trying to override the property via -J command-line argument - refer to your shell documentation as some characters might need escaping.
Another option is defining your property in user.properties file or in a completely separate file and using __FileToString() function to read it

Jenkins active choice parameter not understand the "#" symbol" and encodes it. How can one decode it while passing it as parameter in build command?

Groovy script to pass parameter tag value dynamically on the basis of project
Once configured, the # in the value is encoded, I want to avoid that

Is it possible to pass a multi-word argument on command-line when all arguments are already covered in double quotes?

Here is what I am trying to do, pass TCL script and parameters to Libero.exe. The method is given in document DS50003100B page 20 as follows:
C:\libero\designer\bin\libero SCRIPT:testTclparam.tcl “SCRIPT_ARGS:a b c”
LOGFILE:testTclparam.log
I am not sure why the SCRIPT_ARGS is surrounded by double quotes. Anyway, I need to pass in these parameters:
RTG4
RT4G150
352 CQFP
Actel:SgCore:RTG4URAM:1.1.106
The problem is with the third parameter. It is interpreted as two separate paramters, rather than a single value containing space character. The PACKAGE parameter has the form where it has a number and alphabetic value separated by space.
Is there anyway to pass multi-word parameter (a single value containing space) when all parameters are already covered in double quotes?
This does not work:
C:\libero\designer\bin\libero SCRIPT:testTclparam.tcl “SCRIPT_ARGS:RTG4 RT4G150 "352 CQFP" Actel:SgCore:RTG4URAM:1.1.106”
LOGFILE:testTclparam.log
That is why I am on this forum.

In YAML, is there any way to use variables inside a literal block scalar?

I'd like to use a variable inside a YAML literal block scalar.
Here's what I'd like to do:
markup: |
<title>
{{ title }}
</title>
Can that be done somehow?
I appreciate that this example would be trivial to execute without using a literal block scalar, but my actual use case inside a Foundation 6 stack would contain more markup and more variables than what I'm showing here.
There is no such thing as a variable inside a literal block scalar.
First of all there are no variables in YAML (the word variable, occurs only once in the YAML specification, in an example document, nr. 2.28).
And second, this is called literal for a reason. No interpretation is done of any of the characters.
Of course it is possible that some program that loads your document does something with the text between curly braces ({}). E.g interprets it as a jinja2 template. But without knowing what such a program does or expects, it is equally valid to expect something like that for the information between angle brackets (<>).
Therefore within YAML there is no way to use variables, neither inside of literal block-style scalars, nor outside them.
As for the templating: I have worked with program that generated YAML from a template and applied templates on the loaded string scalars (by recursively walking the tree). Your example could be either.

Loading data from YAML in ruby changing the encoding/byte structure of data?

I am trying to write a method to remove some blacklisted characters like bom characters using their UTF-8 values. I am successful to achieve this by creating a method in String class with the following logic,
def remove_blacklist_utf_chars
self.force_encoding("UTF-8").gsub!(config[:blacklist_utf_chars][:zero_width_space].force_encoding("UTF-8"), "")
self
end
Now to make it useful across the applications and reusable I create a config in a yml file. The yml structure is something like,
:blacklist_utf_chars:
:zero_width_space: '"\u{200b}"'
(Edit) Also as suggested by Drenmi this didn't work,
:blacklist_utf_chars:
:zero_width_space: \u{200b}
The problem I am facing is that the method remove_blacklist_utf_chars does not work when I load the utf-encoding of blacklist characters from yml file
But when I directly pass these in the method and not via the yml file the method works.
So basically
self.force_encoding("UTF-8").gsub!("\u{200b}".force_encoding("UTF-8"), "") -- works.
but,
self.force_encoding("UTF-8").gsub!(config[:blacklist_utf_chars][:zero_width_space].force_encoding("UTF-8"), "") -- doesn't work.
I printed the value of config[:blacklist_utf_chars][:zero_width_space] and its equal to "\u{200b}"
I got this idea by referring: https://stackoverflow.com/a/5011768/2362505.
Now I am not sure how what exactly is happening when the blacklist chars list is loaded via yml in ruby code.
EDIT 2:
On further investigation I observed that there is an extra \ getting added while reading the hash from the yaml.
So,
puts config[:blacklist_utf_chars][:zero_width_space].dump
prints:
"\\u{200b}"
But then if I just define the yaml as:
:blacklist_utf_chars:
:zero_width_space: 200b
and do,
ch = "\u{#{config[:blacklist_utf_chars][:zero_width_space]}}"
self.force_encoding("UTF-8").gsub!(ch.force_encoding("UTF-8"), "")
I get
/Users/harshsingh/dir/to/code/utils.rb:121: invalid Unicode escape (SyntaxError)
The "\u{200b}" syntax is used for escaping Unicode characters in Ruby source code. It won’t work inside Yaml.
The equivalent syntax for a Yaml document is the similar "\u200b" (which also happens to be valid in Ruby). Note the lack of braces ({}), and also the double quotes are required, otherwise it will be parsed as literal \u200b.
So your Yaml file should look like this:
:blacklist_utf_chars:
:zero_width_space: "\u200b"
If you puts the value, and get the output "\u{200b}", it means the quotes are included in your string. I.e., you're actually calling:
self.force_encoding("UTF-8").gsub!('"\u{200b}"'.config[:blacklist_utf_chars][:zero_width_space].force_encoding("UTF-8"), "")
Try changing your YAML file to:
:blacklist_utf_chars:
:zero_width_space: \u{200b}

Resources