I'm trying to feed JSON as a String to CloudFormation, and it's not working.

0

I'm trying to schedule an ECS task using a Scheduler::Schedule CFN resource. Everything works fine until I try to encode the "Input" parameter. "Input" expects a String but ECS needs it to be a JSON object and for the life of me I can't make CFN happy.

For example, assuming my JSON object is:

{"containerOverrides":[{"name":"myapp","command":["mycommand"]}]}

I've tried encoding the JSON object using stringify:

"{\"containerOverrides\":[{\"name\":\"myapp\",\"command\":[\"mycommand\"]}]}"

but CFN responds with "Invalid request provided: JSON syntax error in input for the target: [Source: (String)"

I've also tried HTML encoding:

"{"containerOverrides":[{"name":"myapp","command":["mycommand"]}]}"

but I get the same response from CFN.

If I manually update the Schedule using the AWS Console and then export the Schedule using the CLI I can see the plain JSON in the output. So, the Scheduler service is working with JSON but CFN won't process it properly.

profile picture
RNHurt
gefragt vor 3 Monaten179 Aufrufe
1 Antwort
1
Akzeptierte Antwort

I figured out the answer. I was formatting the string incorrectly. In my case I had to use a triple backslash to make CFN happy:

"{\\\"containerOverrides\\\":[{\\\"name\\\":\\\"myapp\\\",\\\"command\\\":[\\\"mycommand\\\"]}]}"
profile picture
RNHurt
beantwortet vor 3 Monaten
  • Thank you for posting this. Wasted a whole day trying to figure this out.

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen