简体   繁体   中英

Cloudformation echo json env variable

My question is similar to this , where I am running into issues with putting JSON into a file. The issue is, no matter how I've formatted my strings inside the userData section of the CloudFormation template, I can't seem to capture an env $variable while maintaining a valid JSON object (with double quotes around the keys and values)

Below are two different ways I've tried to get the object into a file (via echo and cat << EOF < env-config.json ) with virtually every combination of string escaping (single quotes wrapped around double quotes escaped around object keys...etc..)

echo '{\"development\": {\"EnvironmentConfig\": {\"api\": \" 'http://$ip:8000/api' \"}}}' >> env-config.json\n"



cat << EOF > env-config.json
{\"development\": {\"EnvironmentConfig\": {\"api\": \" 'http://$ip:8000/api' \"}}}
EOF

How can I place my perfectly formatted JSON object into a file while capturing an env $variable in it from the userData section of CloudFormation?

Thank you!

edit

Tools involved: gulp-ng-config, bash, cloudformation, json

Using gulp-ng-config to create a module with constants with the env-config.json file

I found out the answer, I needed single quotes around the url portion (as well as the double quotes) of my JSON like the below. This is what the whole line would look like in Cloudformation, I hope this helps someone:

"echo '{\"development\": {\"EnvironmentConfig\": {\"api\": \"'http://$ip:8000/api'\"}}}' >> env-config.json\n",

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM