cloudformation Template format error: Every Resources object must contain a Type member - amazon-vpc

Hi I hope someone can help tell me what I am doing wrong. I am writing a CF template that just adds a VPN Gateway to a VPC. No need to update routing tables etc.
I am using the below template but I get an error that I can't quite see the problem, I thought an extra pair of eyes might help!
:
Template validation error: Template format error: Every Resources object must contain a Type member.
Template:
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "CF Just add a VPN Gateway to a VPC ",
"Parameters" : {
"targetVPCtoAttachGatewayTo" : {
"Description" : "VPC ID to attach VPN Gateway",
"Default" : "vpc-xxxxx",
"Type": "AWS::EC2::VPC::Id"
}
},
"Resources" : {
"VPNGateway" : {
"Type" : "AWS::EC2::VPNGateway",
"Properties" : {
"Type" : "ipsec.1",
"Tags" : [
{"Key": "Name", "Value": {"Fn::Join": ["",["Virtual Private Gateway for ", { "Ref": "targetVPCtoAttachGatewayTo"} ] ]}}]
}
},
"AttachVpnGateway" : {
"Type" : "AWS::EC2::VPCGatewayAttachment",
"DependsOn" : "VPNGateway",
"Properties" : {
"VpcId" : { "Ref" : "targetVPCtoAttachGatewayTo" },
"VpnGatewayId" : { "Ref" : "VPNGateway" }
}
},
"Outputs" : {
}}}

Resolved the issue, curly brackets in the wrong place. Working template below.
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "CF Just add a VPN Gateway to a VPC ",
"Parameters" : {
"targetVPCtoAttachGatewayTo" : {
"Description" : "VPC ID to attach VPN Gateway",
"Default" : "vpc-xxxxx",
"Type": "AWS::EC2::VPC::Id"
}
},
"Resources" : {
"VPNGateway" : {
"Type" : "AWS::EC2::VPNGateway",
"Properties" : {
"Type" : "ipsec.1",
"Tags" : [
{"Key": "Name", "Value": {"Fn::Join": ["",["Virtual Private Gateway for ", { "Ref": "targetVPCtoAttachGatewayTo"} ] ]}}]
}
},
"AttachVpnGateway" : {
"Type" : "AWS::EC2::VPCGatewayAttachment",
"DependsOn" : "VPNGateway",
"Properties" : {
"VpcId" : { "Ref" : "targetVPCtoAttachGatewayTo" },
"VpnGatewayId" : { "Ref" : "VPNGateway" }
}
}
},
"Outputs" : {
}}

Related

Cloudformation template with multiple resources

I have a fairly simple cloudformation template. I am trying to learn about them. I created one where I am trying to create 2 dyanmo table when I deploy the stack. But only one table gets created. Not two. I am not sure what is wrong with my syntax. Pasting the json below
"AWSTemplateFormatVersion" : "2010-09-09",
"Resources" : {
"resource1" : {
"Type" : "AWS::DynamoDB::Table",
"Properties" : {
"AttributeDefinitions" : [
{
"AttributeName" : "Name",
"AttributeType" : "S"
},
{
"AttributeName" : "Age",
"AttributeType" : "S"
}
],
"KeySchema" : [
{
"AttributeName" : "Name",
"KeyType" : "HASH"
},
{
"AttributeName" : "Age",
"KeyType" : "RANGE"
}
],
"ProvisionedThroughput" : {
"ReadCapacityUnits" : "5",
"WriteCapacityUnits" : "5"
},
"TableName" : "tablecloudformation3_1"
}
}
},
"Resources" : {
"resource2" : {
"Type" : "AWS::DynamoDB::Table",
"Properties" : {
"AttributeDefinitions" : [
{
"AttributeName" : "Name",
"AttributeType" : "S"
},
{
"AttributeName" : "Age",
"AttributeType" : "S"
}
],
"KeySchema" : [
{
"AttributeName" : "Name",
"KeyType" : "HASH"
},
{
"AttributeName" : "Age",
"KeyType" : "RANGE"
}
],
"ProvisionedThroughput" : {
"ReadCapacityUnits" : "5",
"WriteCapacityUnits" : "5"
},
"TableName" : "tablecloudformation3_2"
}
}
},
}
There are few mistakes in the template. One already pointed out by #MariaInesParnisari.
The other ones are missing open bracket and unneeded brackets in the middle.
I fixed the template and can confirm it works:
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Resources" : {
"resource1" : {
"Type" : "AWS::DynamoDB::Table",
"Properties" : {
"AttributeDefinitions" : [
{
"AttributeName" : "Name",
"AttributeType" : "S"
},
{
"AttributeName" : "Age",
"AttributeType" : "S"
}
],
"KeySchema" : [
{
"AttributeName" : "Name",
"KeyType" : "HASH"
},
{
"AttributeName" : "Age",
"KeyType" : "RANGE"
}
],
"ProvisionedThroughput" : {
"ReadCapacityUnits" : "5",
"WriteCapacityUnits" : "5"
},
"TableName" : "tablecloudformation3_1"
}
},
"resource2" : {
"Type" : "AWS::DynamoDB::Table",
"Properties" : {
"AttributeDefinitions" : [
{
"AttributeName" : "Name",
"AttributeType" : "S"
},
{
"AttributeName" : "Age",
"AttributeType" : "S"
}
],
"KeySchema" : [
{
"AttributeName" : "Name",
"KeyType" : "HASH"
},
{
"AttributeName" : "Age",
"KeyType" : "RANGE"
}
],
"ProvisionedThroughput" : {
"ReadCapacityUnits" : "5",
"WriteCapacityUnits" : "5"
},
"TableName" : "tablecloudformation3_2"
}
}
}
}
More generally, the CloudFormation Linter can help catch these template issues faster with errors like:
E0000 Duplicate found "Resources" (line 35)

Need find query for dynamic multiple nested collections in mongodb

I need to find collections based nested on values.But my collection having dynamic values . See below code. In which image name keys are dynamic ( _DSC9691.jpg , _DSC9514.JPG ) and " key1 " is dynamic items. Now I need to find collection based on component, material, Subtype
{
"_id" : ObjectId("5ce2df8498f10b276cb466c4"),
"num" : "1",
"lat" : "39.941436099965",
"lon" : "-86.0691700063581",
"images" : {
"_DSC9691.jpg" : {
"key1" : {
"component" : "Sleeve",
"condition" : "",
"sub_type" : {
"Auto Sleeve" : true
},
"material" : "",
"misc" : ""
}
}
}}
{
"_id" : ObjectId("5ce2df8498f10b276cb466c7"),
"num" : "4",
"lat" : "39.9413828961847",
"lon" : "-86.0715084495015",
"images" : {
"_DSC9554.JPG" : {
},
"_DSC9514.JPG" : {
},
"_DSC9622.JPG" : {
}
}}
#Nagendran you won't be able to perform those operations because the nested document that you want to watch isn't named properly. I suggest you to rename that field using a common name and try to use the code bellow. Also remember to not use blank spaces on field names like "Auto Sleeve".
Object:
{
"_id" : ObjectId("5ce2df8498f10b276cb466c7"),
"num" : "4",
"lat" : "39.9413828961847",
"lon" : "-86.0715084495015",
"images" : [
{
"name" : "some name",
"key":
{
"component" : "Sleeve",
"condition" : "",
"sub_type" : {
"Auto_Sleeve" : true
},
"material" : "",
"misc" : ""
},
},
{
"name" : "some name 2",
"key":
{
"component" : "Sleeve 2",
"condition" : "",
"sub_type" : {
"Auto_Sleeve" : true
},
"material" : "",
"misc" : ""
},
},
]
}
Query:
db.collection.find({
"images.key.sub_type.Auto_Sleeve": true
})
If you want you can use aggregation framework to filter inside the "images" nested document.
To get a litle bit more information you can access:
https://docs.mongodb.com/manual/aggregation/
https://docs.mongodb.com/manual/tutorial/query-documents/
https://www.mongodb.com/blog/post/6-rules-of-thumb-for-mongodb-schema-design-part-1
https://university.mongodb.com/

swagger file for all possible 'properties'

I need to call an API to load data on an ongoing basis. API returns different properties for each event. When I create the swagger file it has properties from sample return, but in the long run there will be more properties which can be added by the source system and they will not be in swagger file.
Is there any way to recreate swagger file before data load dynamically with additional properties?
Swagger file is generated by Informatica Cloud based on a sample return while testing the connection.
Properties list has a different number of entries based on event type.
swagger file:
{"swagger" : "2.0",
"info" : {
"description" : null,
"version" : "1.0.0",
"title" : null,
"termsOfService" : null,
"contact" : null,
"license" : null
},
"host" : "<host>.com",
"basePath" : "/api",
"schemes" : [ "https" ],
"paths" : {
"/2.0" : {
"post" : {
"tags" : [ "events" ],
"summary" : null,
"description" : null,
"operationId" : "events",
"produces" : [ "application/json" ],
"consumes" : [ "application/json" ],
"parameters" : [ {
"name" : "script",
"in" : "query",
"description" : null,
"required" : false,
"type" : "string"
}, {
"name" : "Authorization",
"in" : "header",
"description" : null,
"required" : false,
"type" : "string"
} ],
"responses" : {
"200" : {
"description" : "successful operation",
"schema" : {
"$ref" : "#/definitions/events"
}
}
}
}
}
},
"definitions" : {
"events##properties" : {
"properties" : {
"$app_build_number" : {
"type" : "string"
},
"$app_version_string" : {
"type" : "string"
},
"$carrier" : {
"type" : "string"
},
"$lib_version" : {
"type" : "string"
},
"$manufacturer" : {
"type" : "string"
},
"$model" : {
"type" : "string"
},
"$os" : {
"type" : "string"
},
"$os_version" : {
"type" : "string"
},
"$radio" : {
"type" : "string"
},
"$region" : {
"type" : "string"
},
"$screen_height" : {
"type" : "number",
"format" : "int32"
},
"$screen_width" : {
"type" : "number",
"format" : "int32"
},
"Home Step Enabled" : {
"type" : "string"
},
"Number Of Lifetime Logins" : {
"type" : "number",
"format" : "int32"
},
"Sessions" : {
"type" : "number",
"format" : "int32"
},
"mp_country_code" : {
"type" : "string"
},
"mp_lib" : {
"type" : "string"
}
}
},
"events" : {
"properties" : {
"name" : {
"type" : "string"
},
"distinct_id" : {
"type" : "string"
},
"labels" : {
"type" : "string"
},
"time" : {
"type" : "number",
"format" : "int64"
},
"sampling_factor" : {
"type" : "number",
"format" : "int32"
},
"dataset" : {
"type" : "string"
},
"properties" : {
"$ref" : "#/definitions/events##properties"
}
}
}
}
}
sample return:
"name": "Session",
"distinct_id": "1234567890",
"labels": [],
"time": 1520072505000,
"sampling_factor": 1,
"dataset": "$event_data_set",
"properties": {
"$app_build_number": "900",
"$app_version_string": "1.9",
"$carrier": "AT&T",
"$lib_version": "2.0.1",
"$manufacturer": "Apple",
"$model": "iPhone10,6",
"$os": "iOS",
"$os_version": "11.2.6",
"$radio": "LTE",
"$region": "Florida",
"$screen_height": 667,
"$screen_width": 375,
"Number Of Lifetime Logins": 2,
"Session Length": "00h:00m:08s",
"Sessions": 43,
"mp_country_code": "US",
"mp_lib": "swift"
}
}

retrieving vavr collection via spring data rest from mongo db doesn't work

I created a small spring boot project to retrieve a sample object from mongoDb via spring data rest which contains a Seq (vavr collection). Immediately after booting the app it doesn't work. At first I have to do an insertion and afterwards it works to call teh repo's rest endpoint.
Error msg from log
Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Couldn't find PersistentEntity for type class io.vavr.collection.List$Cons!; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Couldn't find PersistentEntity for type class io.vavr.collection.List$Cons! (through reference chain: org.springframework.hateoas.PagedResources["_embedded"]->java.util.Collections$UnmodifiableMap["myEntities"]->java.util.ArrayList[0]->org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$PersistentEntityResourceSerializer$1["content"]->de.spring.demo.entity.MyEntity["myList"])
It sounds like some mappers have to be injected which are automatically injected after inserting a new entry (or some lazy loading maybe...)
A sample can be found here: https://github.com/renne-b/spring-rest-demo
It would be great to get a hint what's missing.
some details:
latest spring boot milestone: 2.0.0.M3
I registered VavrModule at ObjectMapper
#EnableMongoRepositories(basePackages = "for my path to classes")
I update your project with
Spring boot 2.0.0.RELEASE
EmbeddedMongo de.flapdoodle.embed:de.flapdoodle.embed.mongo:2.0.3 / 3.2.2:Windows:B64
Fix JSON mapping
And after that request curl http://localhost:8080/myEntities executed without problems:
{
"_embedded" : {
"myEntities" : [ ]
},
"_links" : {
"self" : {
"href" : "http://localhost:8080/myEntities{?page,size,sort}",
"templated" : true
},
"profile" : {
"href" : "http://localhost:8080/profile/myEntities"
}
},
"page" : {
"size" : 20,
"totalElements" : 0,
"totalPages" : 0,
"number" : 0
}
}
After add 2 entities:
{
"_embedded" : {
"myEntities" : [ {
"foo" : "bar1521033137701",
"myList" : {
"content" : [ "bla" ]
},
"_links" : {
"self" : {
"href" : "http://localhost:8080/myEntities/5aa91fb1bec7c7169c9b5943"
},
"myEntity" : {
"href" : "http://localhost:8080/myEntities/5aa91fb1bec7c7169c9b5943"
}
}
}, {
"foo" : "bar1521033145175",
"myList" : {
"content" : [ "bla" ]
},
"_links" : {
"self" : {
"href" : "http://localhost:8080/myEntities/5aa91fb9bec7c7169c9b5944"
},
"myEntity" : {
"href" : "http://localhost:8080/myEntities/5aa91fb9bec7c7169c9b5944"
}
}
} ]
},
"_links" : {
"self" : {
"href" : "http://localhost:8080/myEntities{?page,size,sort}",
"templated" : true
},
"profile" : {
"href" : "http://localhost:8080/profile/myEntities"
}
},
"page" : {
"size" : 20,
"totalElements" : 2,
"totalPages" : 1,
"number" : 0
}
}

How do I create a subnet for AWS ElastiCache?

I came across of creating 2 subnet for elasticache to use via cloudformation template.
The code example is below.
"SubnetGroup" : {
"Type" : " "SubnetIds" : [ { "Ref" : "Subnet1" }, { "Ref" : "Subnet2" } ]",
"Properties" : {
"Description" : "Cache Subnet Group",
"SubnetIds" : [ { "Ref" : "Subnet1" }, { "Ref" : "Subnet2" } ]
}
}
I understand the logic of the object but what i don't know how to create is the
"SubnetIds" : [ { "Ref" : "**Subnet1**" }, { "Ref" : "**Subnet2**" } ]
I dont know if the object aws:ec2::subnet is capable of creating a subnet for object "AWS::ElastiCache::SubnetGroup".
*"SubnetIds" : [ { "Ref" : "**Subnet1**" }, { "Ref" : "**Subnet2**" } ]*
Can the code below create a subnet for "AWS::ElastiCache::SubnetGroup"?:
"Subnet": {
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"AvailabilityZone" : String,
"CidrBlock" : String,
"Tags" : [ EC2 Tag, ... ],
"VpcId" : { "Ref" : String }
}
}
Or is there "AWS::ElastiCache::Subnet" to create a subnet for elasticache purpose only which I don't find in the docs?
The answer is yes - you reference an AWS::EC2::Subnet from AWS::ElastiCache::SubnetGroup. Here is an example from my code:
The subnet:
"subnet9732c5f2": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"CidrBlock": "10.5.2.0/24",
"AvailabilityZone": "eu-west-1b",
"VpcId": {
"Ref": "vpcc140a7a4"
},
"Tags": [
{
"Key": "Name",
"Value": "Private subnet #2"
}
]
}
}
The subnet group:
"cachesubnetgroup": {
"Type" : "AWS::ElastiCache::SubnetGroup",
"Properties" : {
"Description" : "Cache Subnet for UAT",
"SubnetIds" : [
{
"Ref" : "subnet9732c5f2"
},
{
"Ref" : "AnotherSubnetId"
}
]
}
}