I am having trouble getting the AWS cli working nicely with a bash variable. The AWS cli command takes in a JSON string as a parameter. However, within this json string I am using a variable $SCHEMA_DEFINITION
which itself is a JSON string. For some reason the double quotes are being removed from $SCHEMA_DEFINITION
and making it invalid JSON. How can I preserve these quotes and still produce a valid AWS command?
aws glue create-schema --cli-input-json '{"RegistryId": {"RegistryName": "hxp-schema-registry"},"SchemaName": "'$modelClassName'","DataFormat": "AVRO","Compatibility": "FULL_ALL","SchemaDefinition": "'"$SCHEMA_DEFINITION"'"}'
Gives the error:
An error occurred (InvalidInputException) when calling the CreateSchema operation: Schema definition of AVRO data format is invalid: Unexpected character ('n' (code 110)): was expecting double-quote to start field name at [Source: (String)"{name:hello}"
Here is how I set the variable: SCHEMA_DEFINITION={"name":"Hello"}
{name:Hello}
or{"name":"Hello"}
?{"name":"Hello"}
, the first is not valid json for the command which is what the error seems to be telling me as far as I can tell"{\"name\":\"Hello\"}"
)?SCHEMA_DEFINITION="{\"name\":\"Hello\"}"
Then with command:aws glue create-schema --cli-input-json '{"RegistryId": {"RegistryName": "hxp-schema-registry"},"SchemaName": "'$modelClassName'","DataFormat": "AVRO","Compatibility": "FULL_ALL","SchemaDefinition": "'$SCHEMA_DEFINITION'"}'
And it tells me invalid JSONError parsing parameter 'cli-input-json': Invalid JSON received.
SCHEMA_DEFINITION='{\"name\":\"Hello\"}'
. Note the single quotes.