简体   繁体   English

Cloudformation echo json env变量

[英]Cloudformation echo json env variable

My question is similar to this , where I am running into issues with putting JSON into a file. 我的问题与类似,在这里我遇到了将JSON放入文件的问题。 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) 问题是,无论我如何在CloudFormation模板的userData部分中格式化字符串,我似乎都无法在保持有效JSON对象的同时捕获env $ variable(在键和值两边加上双引号)

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..) 下面是我尝试将对象放入文件的两种不同方法(通过echocat << EOF < env-config.json ),实际上每个字符串都转义了字符串(将单引号引起来的双引号引起了对象键的转义)。 ..等等..)

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? 如何从CloudFormation的userData部分中捕获环境变量$ en时将格式完全正确的JSON对象放入文件中?

Thank you! 谢谢!

edit 编辑

Tools involved: gulp-ng-config, bash, cloudformation, json 涉及的工具:gulp-ng-config,bash,cloudformation,json

Using gulp-ng-config to create a module with constants with the env-config.json file 使用gulp-ng-config使用带有env-config.json文件的常量创建模块

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. 我找到了答案,如下所示,我需要在JSON的url部分(以及双引号)周围使用单引号。 This is what the whole line would look like in Cloudformation, I hope this helps someone: 这就是整行在Cloudformation中的样子,我希望这对某人有帮助:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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