This question is in reference to Atlassian Documentation: Variables for deployment environments
Ask your question here...
Bamboo does not parse variable content in any way, i.e. the content is always just a string. The problem you are encountering is passing a JSON string as a parameter to AWS CloudFormation via the AWS CloudFormation Stack task, which expects those parameters to be passed into the Parameters field as a JSON string in turn, e.g.:
[ { "ParameterKey": "LambdaPolicy", "ParameterValue": "${bamboo.lambda.LambdaPolicy}" } ]
When ${bamboo.lambda.LambdaPolicy} contains just the original JSON, the resulting nested JSON is invalid and triggers the encountered MalformedJsonException.
${bamboo.lambda.LambdaPolicy}
MalformedJsonException
In order to pass a JSON string inside another JSON string in such a scenario, you need to escape it (e.g. manually via JSON Escape/Unescape).
Given your example JSON input:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents" ], "Resource": "arn:aws:logs:*:*:*" }, { "Effect": "Allow", "Action": [ "apigateway:*" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "iam:PassRole", "iam:GetServerCertificate" ], "Resource": "*" } ] }
You would need to pass the following escaped JSON string instead (i.e. as the value of ${bamboo.lambda.LambdaPolicy} in your scenario):
{\n \"Version\": \"2012-10-17\",\n \"Statement\": [\n {\n \"Effect\": \"Allow\",\n \"Action\": [\n \"logs:CreateLogGroup\",\n \"logs:CreateLogStream\",\n \"logs:PutLogEvents\"\n ],\n \"Resource\": \"arn:aws:logs:*:*:*\"\n },\n {\n \"Effect\": \"Allow\",\n \"Action\": [\n \"apigateway:*\"\n ],\n \"Resource\": \"*\"\n },\n {\n \"Effect\": \"Allow\",\n \"Action\": [\n \"iam:PassRole\",\n \"iam:GetServerCertificate\"\n ],\n \"Resource\": \"*\"\n }\n ]\n}
This will yield the same results as passing the unescaped JSON via the AWS Management Console, where the problem does not exist due to its more advanced UI, which accepts each parameter via an individual text input field.
Here's the corresponding Bamboo log output for a variable:
Substituting variable: ${bamboo.lambda.LambdaPolicy} with { \"Version\": \"2012-10-17\", \"Statement\": [ { \"Effect\": \"Allow\", \"Action\": [ \"logs:CreateLogGroup\", \"logs:CreateLogStream\", \"logs:PutLogEvents\" ], \"Resource\": \"arn:aws:logs:*:*:*\" }, { \"Effect\": \"Allow\", \"Action\": [ \"apigateway:*\" ], \"Resource\": \"*\" }, { \"Effect\": \"Allow\", \"Action\": [ \"iam:PassRole\", \"iam:GetServerCertificate\" ], \"Resource\": \"*\" } ] }
And here's the resulting Bamboo log output after the variable has been used inside the Parameters field:
... bamboo.custom.aws.cfn.stack.resources.tst-1-TST-AWSB-CFNPJ-21-2.parameters.LambdaPolicy: { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents" ], "Resource": "arn:aws:logs:*:*:*" }, { "Effect": "Allow", "Action": [ "apigateway:*" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "iam:PassRole", "iam:GetServerCertificate" ], "Resource": "*" } ]}
In other words, the escaped JSON input properly ends up in CloudFormation as an unescaped JSON parameter.
I realize that this escaping requirement poses a notable usability issue (the Parameters field inline dialog examples have a a small hint that "Reserved JSON characters in Bamboo variable content need to be escaped at runtime", however, it had been missing in the task documentation, and either way this is not easily discovered). I've filed UAA-203 to contemplate how to improve the usability in this regard (suggestions welcome).
Initial Answer
We have outlined a more generic solution for Utoolity's Bamboo add-ons in our KB article How to supply task input from an external source like a file - here's a slightly adjusted version for your JSON use case:
You want to inject a JSON object into a Bamboo variable:
cloudformation.parameters
${bamboo.cloudformation.parameters}
This workaround has the limitation that the included content cannot use Bamboo variables in turn, because Bamboo doesn't yet support nested/recursive expansion of variables - see https://jira.atlassian.com/browse/BAM-8266.
Hi @Ramesh Ramalingam
you can find related here JsonObject article please go through this.
might be it helps you.
Hi Stephen,
Thanks for your reply.
I think regardless of where the inputs are coming from (file, plan variables, etc.), bamboo is still parsing the input before sending it to AWS or any other tool. So the parsing is happening after the value is supplied to the parameters. So I am not sure whether this will still work. I could be wrong but I will still give it a go. Thanks.
Thanks Yogesh. I will read through and see if I can get anything out of it. Thanks.
image2016-8-10 11:24:18.png
@Ramesh Ramalingam - thank you for using our add-ons.I've just confirmed that our resp. integration test for the referenced How to still work as documented. Accordingly, the MalformedJsonException you are encountering is hinting on this being caused by an actual JSON syntax error, specifically a missing brace ('Unterminated object') - I can think of the following possible causes:
Hope this helps - if not, could you please make the offending JSON available so that we can try to reproduce this (and of course, feel free to create a support request, if you'd prefer to take this offline)?
It looks like you're new here. Sign in or register to get started.