rbind DHS data labelled - rbind

For the context: For downloading DHS data I follow this link: https://rspatialdata.github.io/dhs-data.html#Loading_datasets_and_associating_its_metadata_into_R
I want to analyze it following this post: https://github.com/DHSProgram/DHS-Indicators-R/commit/1c64b0f2af33ac56d149a7dbce34ea8bb21ce3f9
Since I have data from 5 countries, starting in 2000 I joined HW files to PR files, where the orginal PR files did't have the hc (undernourishment) variables. The merge of HW files to PR files ended up the comb_extract_HW_res dataframe. However, when I want to bind my comb_extract_HW_res to the other dataframes (which files already included the hc variables) comb_extract by rbin_labelled (as I did for example to create comb_extact and everything just worked fine). But in this step (combining comb_extract which already contained hc variables and comb_extract_HW_res, where I added the variables) I somehow loosing all my negative values of my hc variables. Someone have an idea how this happens?
comb_extract_all <- rbind_labelled(list(comb_extract, comb_extract_HW_res), labels = list(hv023 ="concatenate", hv024 = "concatenate", hc70 = "concatenate", hc71 = "concatenate", hc72 = "concatenate", hc73 = "concatenate"))
my two dfs are:
dput(comb_extract[1:3,1:10])
structure(list(hhid = c(" 1 27", " 1 27", " 1 27"
), hv001 = c(1, 1, 1), hv002 = c(27, 27, 27), hv005 = c(1707326,
1707326, 1707326), hv006 = c(8, 8, 8), hv007 = c(2003, 2003,
2003), hv021 = c(1, 1, 1), hv023 = structure(c(34L, 34L, 34L), labels = structure(1:343, names = c("1",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "2",
"20", "21", "22", "23", "24", "25", "3", "4", "5", "6", "7",
"8", "9", "Acholi", "Addis Ababa", "Afar-rural", "Afar-Urban",
"Affar rural", "Affar urban", "Amhara-rural", "Amhara-urban",
"Amhara rural", "Amhara urban", "Ankole", "Balaka - rural", "Balaka - urban",
"Benishangul-Gumuz-rural", "Benishangul-Gumuz-urban", "Benishangul-Gumuz rural",
"Benishangul-Gumuz urban", "Blantyre - rural", "Blantyre - urban",
"Bomi - Rural", "Bomi - Urban", "Bomi Rural", "Bomi Urban", "Bong - Rural",
"Bong - Urban", "Bong Rural", "Bong Urban", "Bugesera", "Bugesera - rural",
"Bugesera - urban", "Bugisu", "Bukedi", "Bulawayo - Urban", "Bunyoro",
"Burera", "Burera - rural", "Burera - urban", "Busoga", "Central",
"Central 1", "Central 2", "Chikwawa - rural", "Chikwawa - urban",
"Chiradzulu - rural", "Chiradzulu - urban", "Chitipa - rural",
"Chitipa - urban", "Dedza - rural", "Dedza - urban", "Dire Dawa-urban",
"Dire Dawa -rural", "Dire Dawa rural", "Dire Dawa urban", "Dowa - rural",
"Dowa - urban", "East Central", "East Central Island-rural",
"Eastern", "Gakenke", "Gakenke - rural", "Gakenke - urban", "Gambela-rural",
"Gambela-urban", "Gambela rural", "Gambela urban", "Gasabo",
"Gasabo - rural", "Gasabo - urban", "Gatsibo", "Gatsibo - rural",
"Gatsibo - urban", "Gbarpolu - Rural", "Gbarpolu - Urban", "Gbarpolu Rural",
"Gbarpolu Urban", "Gicumbi", "Gicumbi - rural", "Gicumbi - urban",
"Gisagara", "Gisagara - rural", "Gisagara - urban", "Grand Bassa - Rural",
"Grand Bassa - Urban", "Grand Bassa Rural", "Grand Bassa Urban",
"Grand Cape Mount - Rural", "Grand Cape Mount - Urban", "Grand Cape Mount Rural",
"Grand Cape Mount Urban", "Grand Gedeh - Rural", "Grand Gedeh - Urban",
"Grand Gedeh Rural", "Grand Gedeh Urban", "Grand Kru - Rural",
"Grand Kru - Urban", "Grand Kru Rural", "Grand Kru Urban", "Harare - Urban",
"Harari-rural", "Harari-urban", "Harari rural", "Harari urban",
"Huye", "Huye - rural", "Huye - urban", "Kamonyi", "Kamonyi - rural",
"Kamonyi - urban", "Kampala", "Karamoja", "Karonga - rural",
"Karonga - urban", "Karongi", "Karongi - rural", "Karongi - urban",
"Kasungu - rural", "Kasungu - urban", "Kayonza", "Kayonza - rural",
"Kayonza - urban", "Kicukiro", "Kicukiro - rural", "Kicukiro - urban",
"Kigezi", "Kirehe", "Kirehe - rural", "Kirehe - urban", "Lango",
"Likoma - rural", "Likoma - urban", "Lilongwe - rural", "Lilongwe - urban",
"Lofa - Rural", "Lofa - Urban", "Lofa Rural", "Lofa Urban", "Machinga - rural",
"Machinga - urban", "Mangochi - rural", "Mangochi - urban", "Manicaland - Rural",
"Manicaland - Urban", "Margibi - Rural", "Margibi - Urban", "Margibi Rural",
"Margibi Urban", "Maryland - Rural", "Maryland - Urban", "Maryland Rural",
"Maryland Urban", "Mashonaland Central - Rural", "Mashonaland Central - Urban",
"Mashonaland East - Rural", "Mashonaland East - Urban", "Mashonaland West - Rural",
"Mashonaland West - Urban", "Masvingo - Rural", "Masvingo - Urban",
"Matabeleland North - Rural", "Matabeleland North - Urban", "Matabeleland South - Rural",
"Matabeleland South - Urban", "Mchinji - rural", "Mchinji - urban",
"Midlands - Rural", "Midlands - Urban", "Montserrado - Rural",
"Montserrado - Urban", "Montserrado Rural", "Montserrado Urban",
"Muhanga", "Muhanga - rural", "Muhanga - urban", "Mulanje - rural",
"Mulanje - urban", "Musanze", "Musanze - rural", "Musanze - urban",
"Mwanza - rural", "Mwanza - urban", "Mzimba - rural", "Mzimba - urban",
"National", "Neno - rural", "Neno - urban", "Ngoma", "Ngoma - rural",
"Ngoma - urban", "Ngororero", "Ngororero - rural", "Ngororero - urban",
"Nimba - Rural", "Nimba - Urban", "Nimba Rural", "Nimba Urban",
"Nkhatabay - rural", "Nkhatabay - urban", "Nkhota kota - rural",
"Nkhota kota - urban", "North ( excluding refugee camps )", "North Buganda",
"North Buganda Island-rural", "North Buganda Island-urban", "Northern",
"Nsanje - rural", "Nsanje - urban", "Ntcheu - rural", "Ntcheu - urban",
"Ntchisi - rural", "Ntchisi - urban", "Nyabihu", "Nyabihu - rural",
"Nyabihu - urban", "Nyagatare", "Nyagatare - rural", "Nyagatare - urban",
"Nyamagabe", "Nyamagabe - rural", "Nyamagabe - urban", "Nyamasheke",
"Nyamasheke - rural", "Nyamasheke - urban", "Nyanza", "Nyanza - rural",
"Nyanza - urban", "Nyarugenge", "Nyarugenge - rural", "Nyarugenge - urban",
"Nyaruguru", "Nyaruguru - rural", "Nyaruguru - urban", "Oromia-rural",
"Oromia-urban", "Oromiya rural", "Oromiya urban", "Phalombe - rural",
"Phalombe - urban", "Refugee camps", "River Cess - Rural", "River Cess - Urban",
"River Gee - Rural", "River Gee - Urban", "River Gee Rural",
"River Gee Urban", "Rivercess Rural", "Rivercess Urban", "Rubavu",
"Rubavu - rural", "Rubavu - urban", "Ruhango", "Ruhango - rural",
"Ruhango - urban", "Rulindo", "Rulindo - rural", "Rulindo - urban",
"Rumphi - rural", "Rumphi - urban", "Rural : Harare", "Rural : Manicaland",
"Rural : Mashonaland Central", "Rural : Mashonaland East", "Rural : Mashonaland West",
"Rural : Masvingo", "Rural : Matabeleland North", "Rural : Matabeleland South",
"Rural : Midlands", "Rusizi", "Rusizi - rural", "Rusizi - urban",
"Rutsiro", "Rutsiro - rural", "Rutsiro - urban", "Rwamagana",
"Rwamagana - rural", "Rwamagana - urban", "S.N.N.P. rural", "S.N.N.P. urban",
"Salima - rural", "Salima - urban", "Sinoe - Rural", "Sinoe - Urban",
"Sinoe Rural", "Sinoe Urban", "SNNPR-rural", "SNNPR-urban", "Somali-rural",
"Somali-urban", "Somali oversample rural", "Somali oversample urban",
"Somali rural", "Somali urban", "South Buganda", "South Buganda Island-rural",
"South Buganda Island-urban", "Southern", "Southwest", "Teso",
"Thyolo - rural", "Thyolo - urban", "Tigray-rural", "Tigray-urban",
"Tigray rural", "Tigray urban", "Tooro", "Urban : Bulawayo",
"Urban : Harare", "Urban : Manicaland", "Urban : Mashonaland Central",
"Urban : Mashonaland East", "Urban : Mashonaland West", "Urban : Masvingo",
"Urban : Matabeleland North", "Urban : Matabeleland South", "Urban : Midlands",
"West Nile", "Western", "Zomba - rural", "Zomba - urban")), class = c("haven_labelled",
"vctrs_vctr", "integer")), hv024 = structure(c(6L, 6L, 6L), labels = structure(1:66, names = c("Acholi",
"Addis Ababa", "Addis Adaba", "Afar", "Affar", "Amhara", "Ankole",
"Benishangul", "Benishangul-Gumuz", "Bugisu", "Bukedi", "Bulawayo",
"Bunyoro", "Busoga", "Central", "Central 1", "Central 2", "Central region",
"Dire Dawa", "East", "East Central", "Eastern", "Gambela", "Harare",
"Harari", "Kampala", "Karamoja", "Kigali", "Kigali City", "Kigezi",
"Lango", "Manicaland", "Mashonaland Central", "Mashonaland East",
"Mashonaland West", "Masvingo", "Matabeleland North", "Matabeleland South",
"Midlands", "Monrovia", "North", "North Buganda", "North Central",
"North Western", "Northern", "Northern region", "Oromia", "Oromiya",
"SNNP", "SNNPR", "Somali", "South", "South Buganda", "South Central",
"South Eastern A", "South Eastern B", "Southern", "Southern region",
"Southwest", "Teso", "Tigray", "Tooro", "West", "West-Nile",
"West Nile", "Western")), class = c("haven_labelled", "vctrs_vctr",
"integer")), hv025 = structure(c(2, 2, 2), labels = c(Urban = 1,
Rural = 2), label = "Type of place of residence", class = c("haven_labelled",
"vctrs_vctr", "double"))), row.names = c("ETPR61SV.1", "ETPR61SV.2",
"ETPR61SV.3"), class = "data.frame")
and
dput(comb_extract_HW_res[1:3,1:10])
structure(list(hhid = c(" 1 1", " 1 1", " 1 1"
), hvidx = c(1, 1, 2), FileName = c("MW", "RW", "MW"), hv001 = c(1,
1, 1), hv002 = c(1, 1, 1), hv005 = c(476295, 1402416, 476295),
hv006 = c(12, 4, 12), hv007 = c(2004, 2005, 2004), hv021 = c(1,
1, 1), hv023 = structure(c(29L, 20L, 29L), labels = structure(1:55, names = c("Addis Ababa - rural",
"Addis Ababa - urban", "Afar - rural", "Afar - urban", "Amhara - rural",
"Amhara - urban", "Ben-Gumz - rural", "Ben-Gumz - urban",
"Blantyre District", "Bulawayo", "Butare", "Byumba", "Cyangugu",
"Dire Dawa - rural", "Dire Dawa - urban", "Gambela - rural",
"Gambela - urban", "Gikongoro", "Gisenyi", "Gitarama", "Harare",
"Harari - rural", "Harari - urban", "Kasungu District", "Kibungo",
"Kibuye", "Kigali Ngali", "Lilongwe District", "Machinga District",
"Mangochi District", "Manicaland", "Mashonaland Central",
"Mashonaland East", "Mashonaland West", "Masvingo", "Matebeleland North",
"Matebeleland South", "Midlands", "Mulanje District", "Mzimba District",
"Oromiya - rural", "Oromiya - urban", "Rest of Malawi", "Ruhengeri",
"Salima District", "SNNP - rural", "SNNP - urban", "Somali - rural",
"Somali - urban", "Thyolo District", "Tigray - rural", "Tigray - urban",
"Umutara", "Ville de Kigali", "Zomba District")), class = c("haven_labelled",
"vctrs_vctr", "integer"))), row.names = c(NA, 3L), class = "data.frame")

Related

Nifi - Extract list with a jolt

I have a JSON with this array 'itens':
obs: I need to fetch this array when performing the transform.
{
"PreNotaFiscal": {
"numero": "19646801",
"serie": "1",
"observacao": "C5_LVMENSR:REF.PROPOSTA 589112 PEDIDO 034792 - 008|C5_MENNOTA:REF.PROPOSTA 589112 PEDIDO 034792 - 008 PRODUTO IMPORTADO SOB REGIME DE DIFERIMENTO, DEC. N 4.316/95. |C5_LVMENSR:REF.PROPOSTA 589112 PEDIDO 034792 - 008|C5_LVLOGIS:LOCAL DA COLETA SALVADOR: TOPLOG ARMAZENAGEM - VIA URBANA, KM 01 S/N - CIA SUL - SIMOES FILHO/BA - CEP:43700-000",
"modalidadeFrete": 0,
"naturezaOperacao": "",
"canalDistribuicao": "",
"tipoOperacao": 1,
"dataEmissao": "20220513",
"peso": 4.3,
"pesoLiquido": 4.3,
"pesoCubado": 0,
"cubagem": 0.017,
"volumes": 1,
"quantidadeItens": 0,
"valor": 10229.86,
"valorProdutos": 10229.86,
"codigoProduto": "1",
"cnpjUnidade": "",
"prazoCliente": ""
},
"emitente": {
"cnpj": "05917486000140",
"nome": "LIVETECH DA BAHIA INDUSTRIA E COM. S.A",
"fantasia": "LIVETECH DA BAHIA INDUSTRIA E COM. S.A",
"inscricaoEstadual": "63250303",
"logradouro": "RODOVIA BA 262 - POLO DE INFORMATICA DE ILHEUS",
"bairro": "IGUAPE",
"codigoMunicipio": "2913606",
"cep": "45658335",
"fone": "(73) 3222-5250"
},
"destinatario": {
"cnpj": "09356818000116",
"nome": "INTERNET PLAY LTDA",
"fantasia": "NETPLAY",
"inscricaoEstadual": "177269246112",
"email": "financeiro#netplay.net.br",
"bairro": "JARDIM PLANALTO",
"estado": "SP",
"codigoMunicipio": "02804",
"cep": "16072340",
"fone": "(18) 3117-7434"
},
"itens": [
{
"produto": "1000196100663",
"nomeProduto": "XA1DTCHUS - XGS 136 Dispositivo de seguran�a - cabo de alime",
"cubagem": 0.017,
"quantidade": 1,
"volumes": 1,
"valor": 9321.06,
"codigoClassificacaoProduto": "100"
}
],
"volumes": [
{
"item": "01",
"quantidade": 1,
"altura": 0.15,
"largura": 0.28,
"comprimento": 0.41,
"volume": 0.017,
"pesoPorVolume": 4.3,
"pesoTotal": 4.3,
"tipoVolume": "PCT 08"
}
]
}
I transform:
[
{
"operation": "shift",
"spec": {
"PreNotaFiscal": {
"numero": "numero",
"serie": "serie",
"observacao": "observacao",
"modalidadeFrete": "modalidadeFrete",
"naturezaOperacao": "naturezaOperacao",
"canalDistribuicao": "canalDistribuicao",
"tipoOperacao": "tipoOperacao",
"dataEmissao": "dataEmissao",
"peso": "peso",
"pesoLiquido": "pesoLiquido",
"pesoCubado": "pesoCubado",
"cubagem": "cubagem",
"volumes": "volumes",
"quantidadeItens": "quantidadeItens",
"valor": "valor",
"valorProdutos": "valorProdutos",
"codigoProduto": "codigoProduto",
"prazoCliente": "prazoCliente"
},
"emitente": {
"cnpj": "emitente.cnpj",
"nome": "emitente.nome",
"fantasia": "emitente.fantasia",
"inscricaoEstadual": "emitente.inscricaoEstadual",
"logradouro": "emitente.logradouro",
"bairro": "emitente.bairro",
"codigoMunicipio": "emitente.codigoMunicipio",
"cep": "emitente.cep",
"fone": "emitente.fone"
},
"destinatario": {
"cnpj": "destinatario.cnpj",
"nome": "destinatario.nome",
"fantasia": "destinatario.fantasia",
"inscricaoEstadual": "destinatario.inscricaoEstadual",
"email": "destinatario.email",
"bairro": "destinatario.bairro",
"codigoMunicipio": "destinatario.codigoMunicipio",
"cep": "destinatario.cep",
"fone": "destinatario.fone"
}
}
},
{
"operation": "default",
"spec": {
"cnpjUnidade": "${cnpjEmissor:unescapeJson()}"
}
}
]
But I need to bring the values and the array of the "itens", example:
{
"numero" : "19646801",
"serie" : "1",
"observacao" : "C5_LVMENSR:REF.PROPOSTA 589112 PEDIDO 034792 - 008|C5_MENNOTA:REF.PROPOSTA 589112 PEDIDO 034792 - 008 PRODUTO IMPORTADO SOB REGIME DE DIFERIMENTO, DEC. N 4.316/95. |C5_LVMENSR:REF.PROPOSTA 589112 PEDIDO 034792 - 008|C5_LVLOGIS:LOCAL DA COLETA SALVADOR: TOPLOG ARMAZENAGEM - VIA URBANA, KM 01 S/N - CIA SUL - SIMOES FILHO/BA - CEP:43700-000",
"modalidadeFrete" : 0,
"naturezaOperacao" : "",
"canalDistribuicao" : "",
"tipoOperacao" : 1,
"dataEmissao" : "20220513",
"peso" : 4.3,
"pesoLiquido" : 4.3,
"pesoCubado" : 0,
"cubagem" : 0.017,
"volumes" : 1,
"quantidadeItens" : 0,
"valor" : 10229.86,
"valorProdutos" : 10229.86,
"codigoProduto" : "1",
"prazoCliente" : "",
"emitente" : {
"cnpj" : "05917486000140",
"nome" : "LIVETECH DA BAHIA INDUSTRIA E COM. S.A",
"fantasia" : "LIVETECH DA BAHIA INDUSTRIA E COM. S.A",
"inscricaoEstadual" : "63250303",
"logradouro" : "RODOVIA BA 262 - POLO DE INFORMATICA DE ILHEUS",
"bairro" : "IGUAPE",
"codigoMunicipio" : "2913606",
"cep" : "45658335",
"fone" : "(73) 3222-5250"
},
"destinatario" : {
"cnpj" : "09356818000116",
"nome" : "INTERNET PLAY LTDA",
"fantasia" : "NETPLAY",
"inscricaoEstadual" : "177269246112",
"email" : "financeiro#netplay.net.br",
"bairro" : "JARDIM PLANALTO",
"codigoMunicipio" : "02804",
"cep" : "16072340",
"fone" : "(18) 3117-7434"
},
"cnpjUnidade" : "${cnpjEmissor:unescapeJson()}",
"itens": [
{
"produto": "1000196100663",
"nomeProduto": "XA1DTCHUS - XGS 136 Dispositivo de seguran�a - cabo de alime",
"cubagem": 0.017,
"quantidade": 1,
"volumes": 1,
"valor": 9321.06
}
}
If there are more items, they will be inserted together.
Example:
Itens: [{
"produto": "1000196100663",
"nomeProduto": "XA1DTCHUS - XGS 136 Dispositivo de seguran�a - cabo de alime",
"cubagem": 0.017,
"quantidade": 1,
"volumes": 1,
"valor": 9321.06
},
{ "produto": "1000196100663",
"nomeProduto": "XA1DTCHUS - XGS 136 Dispositivo de seguran�a - cabo de alime",
"cubagem": 0.017,
"quantidade": 1,
"volumes": 1,
"valor": 9321.06}
]
Now i detailed with the whole json.
Can someone help me?
No need to rewrite all sub-attibutes, but put only the main nodes within a shift transformation spec, and then remove the extra ones, and default the desired one such as
[
{
"operation": "shift",
"spec": {
"#PreNotaFiscal": "", // bring the object except the key
"emitente": "&", // replicate all listed object as a whole
"destinatario": "&",
"itens": "&"
}
},
{
"operation": "remove",
"spec": {
"itens": {
"*": {
"codigoClas*": ""
}
},
"cnpjUn*": ""
}
},
{
"operation": "default",
"spec": {
"cnpjUnidade": "${cnpjEmissor:unescapeJson()}"
}
}
]
where a suitable abbreviation for the literal codigoClassificacaoProduto such as codigoClas, along with the replacement wildcard * might be used as in the current case.

aws cloudformation template for spot request in ec2 instance

I need a sample cloud formation template to add spot requests while provisioning the ec2 instance in AWS.I have tried with console to provision spot instances but I couldn't find any exact template for add spot request in ec2
You Can create a SpotFleet resource, here's an example
SpotFleet:
Type: AWS::EC2::SpotFleet
Properties:
SpotFleetRequestConfigData:
IamFleetRole: !GetAtt [IAMFleetRole, Arn]
SpotPrice: '1000'
TargetCapacity:
Ref: TargetCapacity
LaunchSpecifications:
- EbsOptimized: 'false'
InstanceType:
Ref: InstanceType
ImageId:
Fn::FindInMap:
- AWSRegionArch2AMI
- Ref: AWS::Region
- Fn::FindInMap:
- AWSInstanceType2Arch
- Ref: InstanceType
- Arch
SubnetId:
Ref: Subnet1
WeightedCapacity: '8'
- EbsOptimized: 'true'
InstanceType:
Ref: InstanceType
ImageId:
Fn::FindInMap:
- AWSRegionArch2AMI
- Ref: AWS::Region
- Fn::FindInMap:
- AWSInstanceType2Arch
- Ref: InstanceType
- Arch
Monitoring:
Enabled: 'true'
SecurityGroups:
- GroupId:
Fn::GetAtt:
- SG0
- GroupId
SubnetId:
Ref: Subnet0
IamInstanceProfile:
Arn:
Fn::GetAtt:
- RootInstanceProfile
- Arn
WeightedCapacity: '8'
You need to create Spot-fleet resource.
Example :
"SpotFleet": {
"Type": "AWS::EC2::SpotFleet",
"Properties": {
"SpotFleetRequestConfigData": {
"IamFleetRole": { "Fn::GetAtt": [ "IAMFleetRole", "Arn"] },
"SpotPrice": "1000",
"TargetCapacity": { "Ref": "TargetCapacity" },
"LaunchSpecifications": [
{
"EbsOptimized": "false",
"InstanceType": { "Ref": "InstanceType" },
"ImageId": { "Fn::FindInMap": [ "AWSRegionArch2AMI", { "Ref": "AWS::Region" },
{ "Fn::FindInMap": [ "AWSInstanceType2Arch", { "Ref": "InstanceType" }, "Arch" ] }
]},
"SubnetId": { "Ref": "Subnet1" },
"WeightedCapacity": "8"
},
{
"EbsOptimized": "true",
"InstanceType": { "Ref": "InstanceType" },
"ImageId": { "Fn::FindInMap": [ "AWSRegionArch2AMI", { "Ref": "AWS::Region" },
{ "Fn::FindInMap": [ "AWSInstanceType2Arch", { "Ref": "InstanceType" }, "Arch" ] }
]},
"Monitoring": { "Enabled": "true" },
"SecurityGroups": [ { "GroupId": { "Fn::GetAtt": [ "SG0", "GroupId" ] } } ],
"SubnetId": { "Ref": "Subnet0" },
"IamInstanceProfile": { "Arn": { "Fn::GetAtt": [ "RootInstanceProfile", "Arn" ] } },
"WeightedCapacity": "8"
}
]
}
}
}
More details can be found in this link :
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-spotfleet.html

Invalid template resource property 'ElbDomainName'

For the below cloudformation template:
AWSTemplateFormatVersion: "2010-09-09"
Description: "Todobackend Stack"
# Stack Parameters
Parameters:
VpcId:
Type: "AWS::EC2::VPC::Id"
Description: "The target VPC Id"
SubnetId:
Type: "AWS::EC2::Subnet::Id"
Description: "The target Subnet Id in availability zone a"
KeyPair:
Type: "String"
Description: "The key pair that is allowed SSH access"
InstanceCount:
Type: "Number"
Description: "The desired number of application instances"
DbSubnets:
Type: "List<AWS::EC2::Subnet::Id>"
Description: "The target DB Subnet Group subnet Ids"
DbAvailabilityZone:
Type: "String"
Description: "The target availability zone for the database instance"
DbUsername:
Type: "String"
Description: "The RDS database username"
DbPassword:
Type: "String"
Description: "The RDS database password"
NoEcho: "true"
# Stack Resources
Resources:
# Configure auto scaing group
AutoScalingGroup:
Type: "AWS::AutoScaling::AutoScalingGroup"
Properties:
VPCZoneIdentifier: [ { "Ref": "SubnetId" } ]
LaunchConfigurationName: { "Ref": "AutoScalingLaunchConfiguration" }
MinSize: 0
MaxSize: 2
DesiredCapacity: { "Ref": "InstanceCount" }
Tags:
- Key: "Name"
Value: { "Fn::Join": ["", [ { "Ref": "AWS::StackName" }, " -instance" ] ] }
PropagateAtLaunch: "true"
AutoScalingLaunchConfiguration:
Type: "AWS::AutoScaling::LaunchConfiguration"
Properties:
ImageId: ami-05958d7635caa4d04
InstanceType: t2.micro
keyName: { "Ref": "KeyPair" }
IamInstanceProfile: { "Ref": "EC2InstanceProfile" }
SecurityGroups:
- { "Ref": "EC2InstanceSecurityGroup" }
UserData: {
"Fn::Base64": { "Fn::Join": ["", [
"#!/bin/bash\n",
"echo ECS_CLUSTER=", { "Ref": "EcsCluster"}, " >> /etc/ecs/ecs.config\n"
] ] }
}
EC2InstanceSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "todobackend-sg"
VpcId: { "Ref": "VpcId" }
SecurityGroupIngress:
- IpProtocol: "tcp"
FromPort: "8080"
ToPort: "8080"
SourceSecurityGroupId: { "Ref": "ElbSecurityGroup" }
- IpProtocol: "tcp"
FromPort: "22"
ToPort: "22"
CidrIp: "0.0.0.0/0"
Tags:
- Key: "Name"
Value: { "Fn::Join": ["", [ { "Ref": "AWS::StackName" }, "-instance-sg" ] ] }
EC2InstanceProfile:
Type: "AWS::IAM::InstanceProfile"
Properties:
Path: "/"
Roles: [ { "Ref": "EC2InstanceRole" } ]
EC2InstanceRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument: {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": [ "ec2.amazonaws.com" ] },
"Action": [ "sts:AssumeRole"]
}
]
}
Path: "/"
ManagePolicyArns:
- "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceForEc2Role"
# Configure RDS
DbInstance:
Type: "AWS::RDS::DBInstance"
Properties:
DBSubnetGroupName: { "Ref": "DbSubnetGroup" }
MultiAZ: "false"
AvailabilityZone: { "Ref": "DBAvailabilityZone" }
AllocatedStorage: 8
StorageType: "gp2"
DBInstanceClass: "db.t2.micro"
DBName: "todobackend"
Engine: "MySQL"
EngineVersion: "5.6"
MasterUserName: { "Ref": "DbUsername" }
MasterUserPassword: { "Ref": "DbPassword" }
VPCSecurityGroups:
- { "Ref": "DbSecurityGroup" }
Tags:
- Key: "Name"
Value: { "Fn::Join": ["", [ { "Ref": "AWS::Stackname" }, "-db" ] ] }
DbSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "Todobackend DB Security Group"
VpcId: { "Ref": "VpcId" }
SecurityGroupIngress:
- IpProtocol: "tcp"
FromPort: "3306"
ToPort: "3306"
SourceSecurityGroupId: { "Ref": "EC2InstanceSecurityGroup" }
DbSubnetGroup:
Type: "AWS::RDS::DBSubnetGroup"
Properties:
DBSubnetGroupDescription: "Todobackend DB Subnet Group"
SubnetIds: { "Ref": "DbSubnets" }
Tags:
- Key: "Name"
Value: { "Fn::Join": ["", [ { "Ref": "AWS::StackName" }, "-db-subnet-group" ] ] }
# Configure ELB
ElasticLoadBalancer:
Type: "AWS::ElasticLoadBalancing::LoadBalancer"
Properties:
CrossZone: "false"
SecurityGroups: [ { "Ref": "ElbSecurityGroup" } ]
Listeners:
- LoadBalancerPort: "80"
InstancePort: "8000"
Protocol: "http"
HealthCheck:
Target: "HTTP:8000/todos"
HealthyThreshold: "2"
UnhealthyThreshold: "10"
Interval: "30"
Timeout: "5"
Subnets: [ { "Ref": "SubnetId" } ]
Tags:
- Key: "Name"
Value: { "Fn::Join": ["", [ { "Ref": "AWS::StackName" }, "-elb" ] ] }
ElbSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "Todobackend ELB Security Group"
VpcId: { "Ref": "VpcId" }
SecurityGroupIngress:
- IpProtocol: "tcp"
FromPort: "80"
ToPort: "80"
CidrIp: "0.0.0.0/0"
Tags:
- Key: "Name"
Value: { "Fn::Join": ["", [ { "Ref": "AWS::StackName" }, "-elb-sg" ] ] }
# Configure ECS
EcsCluster:
Type: "AWS::ECS::EcsCluster"
TodobackendTaskDefinition:
Type: "AWS::ECS::TaskDefinition"
Properties:
ContainerDefinitions:
- Name: todobackend
Image: shamdockerhub/todobackend
Memory: 450
Environment:
- Name: DJANGO_SETTINGS_MODULE
Value: todobackend.settings.release
- Name: MYSQL_HOST
Value: { "Fn::GetAtt": ["DbInstance", "Endpoint.Address"] }
- Name: MYSQL_USER
Value: { "Ref": "DbUsername" }
- Name: MYSQL_PASSWORD
Value: { "Ref": "DbPassword" }
MountPoints:
- ContainerPath: /var/www/todobackend
SourceVolume: webroot
Command:
- uwsgi
- "--socket /var/www/todobackend/todobackend.sock"
- "--chmod-socket=666"
- "--module todobackend.wsgi"
- "--master"
- "--die-on-term"
- Name: nginx
Image: shamdockerhub/todobackend-nginx
Memory: 300
PortMappings:
- ContainerPort: "8000"
HostPort: "8000"
MountPoints:
- ContainerPath: /var/www/todobackend
SourceVolume: webroot
Volumes:
- Name: webroot
Host:
SourcePath: /ecs/webroot
TodobackendService:
Type: "AWS::ECS::Service"
Properties:
TaskDefinition: { "Ref": "TodobackendTaskDefinition" }
Cluster: { "Ref": "EcsCluster" }
LoadBalancers:
- ContainerName: "nginx"
ContainerPort: "8000"
LoadBalancerName: { "Ref": "ElasticLoadBalancer" }
Role: { "Ref": "EcsServiceRole" }
DesiredCount: 0
EcsServiceRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument: {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [ "ecs.amazonaws.com" ]
},
"Action": [ "sts:AssumeRole"]
}
]
}
Path: "/"
ManagePolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole
TodobackendAdhocTaskDefinition: # Application management task
Type: "AWS::ECS::TaskDefinition"
Properties:
ContainerDefinitions:
- Name: todobackend
Image: shamdockerhub/todobackend
Memory: 245
Environment:
- Name: DJANGO_SETTINGS_MODULE
Value: todobackend.settings.release
- Name: MYSQL_HOST
Value: { "Fn::GetAtt": ["DbInstance", "Endpoint.Address"] }
- Name: MYSQL_USER
Value: { "Ref": "DbUsername" }
- Name: MYSQL_PASSWORD
Value: { "Ref": "DbPassword" }
MountPoints:
- ContainerPath: /var/www/todobackend
SourcePath: webroot
Volumes:
- Name: webroot
Host:
SourcePath: /ecs/webroot
# Stack outputs
Outputs:
ElbDomainName:
Description: "Public DNS name of Elastic Load Balancer"
Value: { "Fn::GetAtt": [ "ElasticLoadBalancer", "DNSName" ] }
EcsCluster:
Description: "Amazon resource name (ARN) of Todobackend Ecs Cluster"
Value: { "Ref": "EcsCluster" }
TodobackendTaskDefinition:
Description: "Amazon resource name (ARN) of Todobackend Task definition"
Value: { "Ref": "TodobackendTaskDefinition"}
TodobackendAdhocTaskDefinition:
Description: "Amazon resource name(ARN) of Todobackend Adhoc Task Definition"
Value: { "Ref": "TodobackendAdhocTaskDefinition" }
TodobackendService:
Description: "Amazon resource name (ARN) of Todobackend service"
Value: { "Ref": "TodobackendService" }
below is the error from Outputs block:
Invalid template resource property 'ElbDomainName'
We need dns name of elastic load balancer to be part of Outputs block of stack
Why 'ElbDomainName' an invalid property?
The entire Outputs: block is indented a level too far. Outputs: should not be underneath Resources: indentation-wise
Outputs documentation

Packer Unable to attach EBS Volume

I am trying to attach additional volume to my ami, this is my builder section,
"launch_block_device_mappings": [
{
"device_name": "/dev/sda1",
"volume_size": 8,
"volume_type": "gp2",
"delete_on_termination": true
},
{
"device_name": "/dev/sdb",
"volume_size": 10,
"volume_type": "gp2",
"delete_on_termination": true
}
],
"ami_block_device_mappings": [
{
"device_name": "/dev/sdb",
"virtual_name": "ephemeral0"
}
]
Please help.
This gives you and additional 10Gb disk available for provisioning:
{
"builders" : [
{
"type" : "amazon-ebs",
"instance_type" : "t2.micro",
"ssh_username" : "ubuntu",
"ami_name" : "packer-ES-{{timestamp}}",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*",
"root-device-type": "ebs"
},
"owners": ["099720109477"],
"most_recent": true
},
"launch_block_device_mappings" : [
{
"device_name" : "/dev/sdb",
"delete_on_termination" : true,
"volume_size" : 10,
"volume_type" : "gp2"
}
],
"ami_block_device_mappings" : [
{
"device_name" : "/dev/sdb",
"delete_on_termination" : true,
"volume_type" : "gp2"
}
]
}
],
"provisioners": [
{
"type": "shell",
"inline": [
"lsblk",
"df -h"
]
}
]
}
Running this you will see:
==> amazon-ebs: Connected to SSH!
==> amazon-ebs: Provisioning with shell script: /var/folders/_t/lsk64yf93xs3slvvtc6b_6mr0000gn/T/packer-shell591343041
amazon-ebs: NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
amazon-ebs: xvda 202:0 0 8G 0 disk
amazon-ebs: └─xvda1 202:1 0 8G 0 part /
amazon-ebs: xvdb 202:16 0 10G 0 disk
amazon-ebs: Filesystem Size Used Avail Use% Mounted on
amazon-ebs: udev 488M 0 488M 0% /dev
amazon-ebs: tmpfs 100M 3.0M 97M 3% /run
amazon-ebs: /dev/xvda1 7.7G 956M 6.8G 13% /
amazon-ebs: tmpfs 496M 0 496M 0% /dev/shm
amazon-ebs: tmpfs 5.0M 0 5.0M 0% /run/lock
amazon-ebs: tmpfs 496M 0 496M 0% /sys/fs/cgroup
amazon-ebs: tmpfs 100M 0 100M 0% /run/user/1000
==> amazon-ebs: Stopping the source instance...
amazon-ebs: Stopping instance, attempt 1
Verifying the results:
env AWS_PROFILE=packer-demo AWS_DEFAULT_REGION=eu-west-1 aws ec2 describe-images --image-ids ami-0a53
cb1f4541b55d4
{
"Images": [
{
"Architecture": "x86_64",
"CreationDate": "2018-07-19T09:52:53.000Z",
"ImageId": "ami-0a53cb1f4541b55d4",
"ImageLocation": "965990659467/packer-ES-1531993870",
"ImageType": "machine",
"Public": false,
"OwnerId": "965990659467",
"State": "available",
"BlockDeviceMappings": [
{
"DeviceName": "/dev/sda1",
"Ebs": {
"Encrypted": false,
"DeleteOnTermination": true,
"SnapshotId": "snap-0e622d809cf0e148a",
"VolumeSize": 8,
"VolumeType": "gp2"
}
},
{
"DeviceName": "/dev/sdb",
"Ebs": {
"Encrypted": false,
"DeleteOnTermination": false,
"SnapshotId": "snap-0c65cdcdb579f21b4",
"VolumeSize": 10,
"VolumeType": "standard"
}
},
{
"DeviceName": "/dev/sdc",
"VirtualName": "ephemeral1"
}
],
"EnaSupport": true,
"Hypervisor": "xen",
"Name": "packer-ES-1531993870",
"RootDeviceName": "/dev/sda1",
"RootDeviceType": "ebs",
"SriovNetSupport": "simple",
"VirtualizationType": "hvm"
}
]
}
If you don't need to provision anything on sdb you can remove the launch_device_mappings section completely and move the volume_size into the ami_device_mappings.

qt: an internal error occurced in the compiler

I am currently writing an Disassembler, now I want to create new strings, like that:
// Disassembler Sourcefile
// better known as DisAsm
#include "disassembler.h"
#include <QString>
Disassembler::Disassembler()
{
QString *_protos = new QString[] { "NOP",
"LD BC,d16",
"LD (BC),A",
"INC BC",
"INC B",
"DEC B",
"LD B,d8",
"RLCA",
"LD (a16),SP",
"ADD HL,BC",
"LD A,(BC)",
"DEC BC",
"INC C",
"DEC C",
"LD C,d8",
"RRCA",
"STOP 0",
"LD DE,d16",
"LD (DE),A",
"INC DE",
"INC D",
"DEC D",
"LD D,d8",
"RLA",
"JR r8",
"ADD HL,DE",
"LD A,(DE)",
"DEC DE",
"INC E",
"DEC E",
"LD E,d8",
"RRA",
"JR NZ,r8",
"LD HL,d16",
"LD (HL+),A",
"INC HL",
"INC H",
"DEC H",
"LD H,d8",
"DAA",
"JR Z,r8",
"ADD HL,HL",
"LD A,(HL+)",
"DEC HL",
"INC L",
"DEC L",
"LD L,d8",
"CPL",
"JR NC,r8",
"LD SP,d16",
"LD (HL-),A",
"INC SP",
"INC (HL)",
"DEC (HL)",
"LD (HL),d8",
"SCF",
"JR C,r8",
"ADD HL,SP",
"LD A,(HL-)",
"DEC SP",
"INC A",
"DEC A",
"LD A,d8",
"CCF",
"LD B,B",
"LD B,C",
"LD B,D",
"LD B,E",
"LD B,H",
"LD B,L",
"LD B,(HL)",
"LD B,A",
"LD C,B",
"LD C,C",
"LD C,D",
"LD C,E",
"LD C,H",
"LD C,L",
"LD C,(HL)",
"LD C,A",
"LD D,B",
"LD D,C",
"LD D,D",
"LD D,E",
"LD D,H",
"LD D,L",
"LD D,(HL)",
"LD D,A",
"LD E,B",
"LD E,C",
"LD E,D",
"LD E,E",
"LD E,H",
"LD E,L",
"LD E,(HL)",
"LD E,A",
"LD H,B",
"LD H,C",
"LD H,D",
"LD H,E",
"LD H,H",
"LD H,L",
"LD H,(HL)",
"LD H,A",
"LD L,B",
"LD L,C",
"LD L,D",
"LD L,E",
"LD L,H",
"LD L,L",
"LD L,(HL)",
"LD L,A",
"LD (HL),B",
"LD (HL),C",
"LD (HL),D",
"LD (HL),E",
"LD (HL),H",
"LD (HL),L",
"HALT",
"LD (HL),A",
"LD A,B",
"LD A,C",
"LD A,D",
"LD A,E",
"LD A,H",
"LD A,L",
"LD A,(HL)",
"LD A,A",
"ADD A,B",
"ADD A,C",
"ADD A,D",
"ADD A,E",
"ADD A,H",
"ADD A,L",
"ADD A,(HL)",
"ADD A,A",
"ADC A,B",
"ADC A,C",
"ADC A,D",
"ADC A,E",
"ADC A,H",
"ADC A,L",
"ADC A,(HL)",
"ADC A,A",
"SUB B",
"SUB C",
"SUB D",
"SUB E",
"SUB H",
"SUB L",
"SUB (HL)",
"SUB A",
"SBC A,B",
"SBC A,C",
"SBC A,D",
"SBC A,E",
"SBC A,H",
"SBC A,L",
"SBC A,(HL)",
"SBC A,A",
"AND B",
"AND C",
"AND D",
"AND E",
"AND H",
"AND L",
"AND (HL)",
"AND A",
"XOR B",
"XOR C",
"XOR D",
"XOR E",
"XOR H",
"XOR L",
"XOR (HL)",
"XOR A",
"OR B",
"OR C",
"OR D",
"OR E",
"OR H",
"OR L",
"OR (HL)",
"OR A",
"CP B",
"CP C",
"CP D",
"CP E",
"CP H",
"CP L",
"CP (HL)",
"CP A",
"RET NZ",
"POP BC",
"JP NZ,a16",
"JP a16",
"CALL NZ,a16",
"PUSH BC",
"ADD A,d8",
"RST 00H",
"RET Z",
"RET",
"JP Z,a16",
"PREFIX CB",
"CALL Z,a16",
"CALL a16",
"ADC A,d8",
"RST 08H",
"RET NC",
"POP DE",
"JP NC,a16",
"???",
"CALL NC,a16",
"PUSH DE",
"SUB d8",
"RST 10H",
"RET C",
"RETI",
"JP C,a16",
"???",
"CALL C,a16",
"???",
"SBC A,d8",
"RST 18H",
"LDH (a8),A",
"POP HL",
"LD (C),A",
"???",
"???",
"PUSH HL",
"AND d8",
"RST 20H",
"ADD SP,r8",
"JP HL",
"LD (a16),A",
"???",
"???",
"???",
"XOR d8",
"RST 28H",
"LDH A,(a8)",
"POP AF",
"LD A,(C)",
"DI",
"???",
"PUSH AF",
"OR d8",
"RST 30H",
"LD HL,SP+r8",
"LD SP,HL",
"LD A,(a16)",
"EI",
"???",
"???",
"CP d8",
"RST 38H" };
}
But now I get an error in the last line/line 256 (means the last line of the complete file).
C:\Users\Jan\Desktop\GB Emulator\gbx00\disassembler.cpp:265: Error: C1001: An internal error has occurred in the compiler.
I have tried to replace the "};" with only an "}" but this didn't works to. How can I fix this?
NOTE: I'll try to translate an C# code into C++/Qt.
If you need to create an array of QStrings it should be:
QString _protos[] = { "NOP",
"LD BC,d16",
"LD (BC),A",
...
"RST 38H" };
instead.