Not sure why I'm getting an error of "Value of property VPCSecurityGroups must be of type List of String" - json

I'm not sure why I'm getting the error that reads "Value of property VPCSecurityGroups must be of type List of String"
I've tried creating a db instance in cloud formation. The name of the security group is: wordpressDBSecurityGroup. I've tried passing the value to the db instance in the following ways:
I tried using FN::GetAtt
"VPCSecurityGroups" : {
"Fn::GetAtt":
[
"wordpressDBSecurityGroup",
"GroupId"]
}
I also tried hard coding the name into the attribute:
"VPCSecurityGroups": "wordpressDBSecurityGroup"
I also tried using the 'Ref' functionality:
"VPCSecurityGroups" : {"Ref": "wordpressDBSecurityGroup"}
Can anyone tell me why I'm getting this error? How should I be doing it?

I forgot to add the brackets to the ref functionality. This fixed the issue.
"VPCSecurityGroups" : [{"Ref": "wordpressDBSecurityGroup"}]

Related

How to use the global variable in another function? [duplicate]

Im writing a small code using Memcache Go API to Get data stored in one of its keys . Here are few of lines of code i used ( got the code from Go app-engine docs )
import "appengine/memcache"
item := &memcache.Item {
Key: "lyric",
Value: []byte("Oh, give me a home"),
}
But the line 2 gives me a compilation error "expected declaration, found 'IDENT' item"
I'm new to Go , not able to figure out the problem
The := Short variable declaration can only be used inside functions.
So either put the item variable declaration inside a function like this:
import "appengine/memcache"
func MyFunc() {
item := &memcache.Item {
Key: "lyric",
Value: []byte("Oh, give me a home"),
}
// do something with item
}
Or make it a global variable and use the var keyword:
import "appengine/memcache"
var item = &memcache.Item {
Key: "lyric",
Value: []byte("Oh, give me a home"),
}
I was getting the same error, but the reason was completely different.
I was using following package name.
package go-example
Seems like, it's not a valid package name. After removing the hyphen, it worked.
This error also shows up when assigning value to a variable whose name is a keyword
Like using var:= 2
This also causes the error "expected declaration, found 'IDENT' item"
So correct the name and it will be fine

Python: create json query

I'm trying to get python to create a json formatted like :
[
{
"machine_working": true
},
{
"MachineName": "TBL165-169",
"MachineType": "Rig Test"
}
]
However, i can seam to do it, this is the code i have currently but its giving me error
this_is_a_dict_too=[]
this_is_a_dict_too = dict(State="on",dict(MachineType="machinetype1",MachineName="MachineType2"))
File "c:\printjson.py", line 40
this_is_a_dict_too = dict(Statedsf="test",dict(MachineType="Rig Test",MachineName="TBL165-169")) SyntaxError: non-keyword arg after
keyword arg
this_is_a_dict_too = [dict(machine_working=True),dict(MachineType="machinetype1",MachineName="MachineType2")]
print(this_is_a_dict_too)
You are trying to make dictionary in dictionary, the error message say that you try to add element without name (corresponding key)
dict(a='b', b=dict(state='on'))
will work, but
dict(a='b', dict(state='on'))
won't.
The thing that you presented is list, so you can use
list((dict(a='b'), dict(b='a')))
Note that example above use two dictionaries packed into tuple.
or
[ dict(a='b'), dict(b='a') ]

Is there a way to create a logic condition in packer provisioner?

I am trying to add a condition so my volume_size: can get two different values depending on what is passed in "-var role="
I've tried something like this :
"volume_size": [{
"Fn::If" : [
".ami_id_bar",
{"foo" : "50"},
{"foo" : "20"}
]
}],
.ami_id_bar is a :
"environment_vars": [
"ami_id_bar={{user `role`}}"
],
that gets it from command line when executing packer
This is the error I get :
error(s) decoding:
'launch_block_device_mappings[0].volume_size' expected type 'int64', got unconvertible type '[]interface {}'
Is it impossible or what am I doing wrong ?
Thank you in advance!
No you can't. Packers templates are logicless. The standard way of achieving the what you want is to use -var-file where each vars file represents a role, e.g.
packer build -var-file=role-A.json template.json
In more complex cases we recommend that you preprocess your template and other files and wrap packer in some build script like make.

JSON error and Run script error

Apologies for any incorrect formatting I am new to these message boards
I am using HTML to customise a Textbox in Spotfire and although I get no errors in the Spotfire client I get the following error when I open the Spotfire analysis in Chrome
{ "titleFontColor":"#999999", "value":<SpotfireControl id="98bb1934a3c14ca2ab598deb672b8e44" />, "valueFontColor":"#010101", "symbol":"%", "min":<SpotfireControl id="0a05e2f1c4094273870d97a23b69efe2" />, "max":<SpotfireControl id="033f79eeccdb46ef982262c3c8a4ed0e" />, "humanFriendly":false, "humanFriendlyDecimal":2, "gaugeWidthScale":2.5, "gaugeColor":"#ebebeb", "label":"", "labelFontColor":"#b3b3b3", "shadowOpacity":0.2, "shadowSize":5, "shadowVerticalOffset":3, "levelColors":["#a9d70b","#f9c802","#ff0000"], "startAnimationTime":100, "startAnimationType":">", "donutStartAngle":90, "hideValue":true, "hideMinMax":true, "hideInnerShadow":false, "noGradient":false, "donut":true, "counter":false, "decimals":0, "formatNumber":false,
"customSectors": [{
"color" : "#D8181C",
"lo" : 0,
"hi" : 1
},{
"color" : "#F5CC0A",
"lo" : 1,
"hi" : 2
},{
"color" : "#50AF28",
"lo" : 2,
"hi" : 3
}] }
I get the following
Error - Unexpected token , in JSON at position 39.
I am very new to HTML and was wondering how I locate position 39 in order to try and find the error?
The second issue I am running into is that HTML displays the Donuts as I would expect in my Spotfire client but when I open the webplayer version the icons are not visible. I have to change tabs in the analysis and then return to the first page for the icons to appear. Is this likely to be an error in my HTML or an error elsewhere?
Thanks
In fact you have several problems,
-First you have to put all this code in one line otherwise "]" or "}" will make an error
-Second you have unexpected characters "<" and "/>" in your json you have to clean your json.
Then you can do in javascript
console.log(your_var)
or
console.log(JSON.parse(your_var))
it will transform in json you json (which is in string format)
We need sources to check what can be the problem.

MongoDB: how to select an empty-key subdocument?

Ahoy! I'm having a very funny issue with MongoDB and, possibly more in general, with JSON. Basically, I accidentally created some MongoDB documents whose subdocuments contain an empty key, e.g. (I stripped ObjectIDs to make the code look nicer):
{
"_id" : ObjectId("..."),
"stats" :
{
"violations" : 0,
"cost" : 170,
},
"parameters" :
{
"" : "../instances/comp/comp20.ectt",
"repetition" : 29,
"time" : 600000
},
"batch" : ObjectId("..."),
"system" : "Linux 3.5.0-27-generic",
"host" : "host3",
"date_started" : ISODate("2013-05-14T16:46:46.788Z"),
"date_stopped" : ISODate("2013-05-14T16:56:48.483Z"),
"copy" : false
}
Of course the problem is line:
"" : "../instances/comp/comp20.ectt"
since I cannot get back the value of the field. If I query using:
db.experiments.find({"batch": ObjectId("...")}, { "parameters.": 1 })
what I get is the full content of the parameters subdocument. My guess is that . is probably ignored if followed by an empty selector. From the JSON specification (15.12.*) it looks like empty keys are allowed. Do you have any ideas about how to solve that?
Is that a known behavior? Is there a use for that?
Update I tried to $rename the field, but that won't work, for the same reasons. Keys that end with . are not allowed.
Update filed issue on MongoDB issue tracker.
Thanks,
Tommaso
I have this same problem. You can select your sub-documents with something like this:
db.foo.find({"parameters.":{$exists:true}})
The dot at the end of "parameters" tells Mongo to look for an empty key in that sub-document. This works for me with Mongo 2.4.x.
Empty keys are not well supported by Mongo, I don't think they are officially supported, but you can insert data with them. So you shouldn't be using them and should find the place in your system where these keys are inserted and eliminate it.
I just checked the code and this does not currently seem possible for the reasons you mention. Since it is allowed to create documents with zero length field names I would consider this a bug. You can report it here : https://jira.mongodb.org
By the way, ironically you can query on it :
> db.c.save({a:{"":1}})
> db.c.save({a:{"":2}})
> db.c.find({"a.":1})
{ "_id" : ObjectId("519349da6bd8a34a4985520a"), "a" : { "" : 1 } }