How do I create a subnet for AWS ElastiCache? - aws-cloudformation

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"
}
]
}
}

Related

Opensearch index mapping field value not searchable

I am new at Opensearch and using this code on DevTools to make media_image_thumbnail_url field not searchable but having error like index already exist.
PUT cars
{
"mappings" : {
"properties" : {
"fields" : {
"properties" : {
"media_image_thumbnail_url" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
},
"enable":false
}
}
}
}
}
}
}
This one solved my issue
PUT cars/_mappings
{
"properties" : {
"fields" : {
"properties" : {
"media_image_thumbnail_url" : {
"type" : "text",
"fields": {
"raw": {
"type": "text",
"index": "false"
}
}
}
}
}
}
}

Mongo Update just one item in an sub-document and add one item in the same sub document

This is the document in my collection
{
"_id" : ObjectId("5d766c18791adb12cc607d49"),
"name" : "myapp",
"openApp" : true,
"appDeveloper" : "Arun",
"environments" : [
{
"environment_id" : ObjectId("5d766c18791adb12cc607d45"),
"environment_name" : "production_env_updated",
"environment_type" : "prod",
"services" : [
{
"service_id" : ObjectId("5d766c18791adb12cc607d46"),
"service_name" : "some_updated",
"service_type" : "..."
},
{
"service_id" : ObjectId("5d766d45791adb12cc607d4a"),
"service_name" : "updated 2",
"service_type" : "..."
}
]
},
{
"environment_id" : ObjectId("5d766c18791adb12cc607d48"),
"environment_name" : "demo_env",
"environment_type" : "stage",
"services" : [
{
"service_id" : ObjectId("5d766d45791adb12cc607d4b"),
"service_name" : "perfectly new",
"service_type" : "perfect"
}
]
}
]
}
I wanted to run a query that would update only "service_id" : ObjectId("5d766c18791adb12cc607d46") within the services-array and then add a new service-object
I executed the below query and doesn't know how to move further
db.app_attributes.update ({"_id" : ObjectId("5d766c18791adb12cc607d49")},
{ '$set': {"environments.services.service_id" : ObjectId("5d766c18791adb12cc607d46") : {
"service_id" : ObjectId("5d766c18791adb12cc607d46"),
"service_name" : "sdfsdf",
"service_type" : "..."
}}}
)
If I understand correctly, you want to update the subdocument whose service_id is ObjectId("5d766c18791adb12cc607d46").
You can do it using the Filtered Positional Operator
db.app_attributes.update(
{"_id" : ObjectId("5d766c18791adb12cc607d49")},
{
$set: {
"environments.$[].services.$[element]": {
"service_id" : ObjectId("5d766c18791adb12cc607d46"),
"service_name" : "Updated Service Name",
"service_type" : "Updated Service Type"
}
}
},
{
arrayFilters: [
{"element.service_id": ObjectId("5d766c18791adb12cc607d46")}
],
multi: true
}
)

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

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" : {
}}

Distinct list of values from embedded document in mongodb

I'm going crazy... I come from the sql world an this is my first real experience with mongodb.
I have a given json/object structure (I know, this is not perfect but it has to be so because of existing data and other applications), stored in a mongodb (v3.4) with Restheart as the http frontend.
The documents look like this
{
"_id" : ObjectId("5855cbc9fc3baea81e937261"),
"_etag" : ObjectId("5855cbc99b971700050d8adc"),
"log" : [
"858489b087f7472dbb8d1012dee4cd5d.d",
NumberLong("12345678901234"),
{
"ext" : {
"text" : "someone did something at somewhere (some street 123) +38 USD",
"markup" : [
[
"user",
{
"plain" : "someone",
"team" : "master"
}
], [
"TEXT",
{
"plain" : " did something at "
}
], [
"location",
{
"name" : "somewhere",
"plain" : "some street 123",
"team" : "master"
}
], [
"TEXT",
{
"plain" : "38"
}
], [
"TEXT",
{
"plain" : "USD"
}
]
],
"category" : 1,
"team" : "master"
}
}
]
}
And I want to get a distinct list of the usern.plain names. Theoretically db.logs.distinct("log.2.ext.markup.0.1.plain") would do exactly what I need. But as far as I understand, there is no way to use db.distinct with Restheart. I tried this using views but it seems, I can not use db.distinct in views too.
This are my experiments...
{ "aggrs" : [
{ "stages" : [
{ "_$project" : { "user" : "$log.2.ext.markup.0.1.plain"}},
{ "_$unwind" : "$user"},
{ "_$unwind" : "$user"},
{ "_$unwind" : "$user"},
{ "_$unwind" : "$user"},
{ "_$unwind" : "$user"},
{ "_$unwind" : "$user"},
{ "_$group" : { "_id" : "$user"}}
],
"type" : "pipeline",
"uri" : "unique_users1"
},
{ "stages" : [
{ "_$match": { "log": { "_$exists": true, "_$ne": null }}},
{ "_$unwind" : "$log"},
{ "_$unwind" : "$log.2"},
{ "_$unwind" : "$log.2.ext"},
{ "_$unwind" : "$log.2.ext.markup"},
{ "_$unwind" : "$log.2.ext.markup.0"},
{ "_$unwind" : "$log.2.ext.markup.0.1"},
{ "_$group" : { "_id" : "$log.2.ext.markup.0.1.plain"}}
],
"type" : "pipeline",
"uri" : "unique_users2"
},
{ "stages" : [
{ "_$match" : {"log" : { "_$exists" : true }}},
{ "_$replaceRoot" : { "newRoot" : { "user": "$log.2.ext.markup.0.1.plain"}}}
],
"type" : "pipeline",
"uri" : "unique_users3"
},
{ "stages" : [
{ "_$group" : { "_id" : 1 , "users" : { "_$addToSet" : "$log.2.ext.markup.0.1.plain"}}}
],
"type" : "pipeline",
"uri" : "unique_users4"
}
]}
But results are... nothing or nearly nothing
{
"_embedded": {
"rh:result": [
{
"_id": 1,
"users": [
[]
]
}
]
},
"_returned": 1,
"_size": 1,
"_total_pages": 1
}

Querying subdocument inside a subdocument of a collection in Mongodb

I have the collection named companies as below.
I want to query the url corresponding to C1S1category1 . I do not know which companyName it belongs and which catergories it belongs to.
Please can you let me know what query I need to use in Mongoshell to query the document having catergoryname as C1S1category1
{"companyName": "C1",
"url": "www.com1",
"categories" : [
{"SlNo" : 1,
"url" : "www.com1",
"subcategories" : [
{
"CatergoryName":"C1S1category1",
"Url" : "www.com3"
},
{
"CatergoryName":"C1S1category2",
"Url" : "www.com3"
}
]
},
{
"SlNo" : 2,
"url" : "www.com1",
"subcategories" : [
{
"CatergoryName":"C1S2category1",
"Url" : "www.com3"
},
{
"CatergoryName":"C1S2category2",
"Url" : "www.com3"
}
]
}
]
},
{"companyName": "C2",
"url": "www.com21",
"categories" : [
{"SlNo" : 1,
"url" : "www.com22",
"subcategories" : [
{
"CatergoryName":"C2S1category1",
"Url" : "www.com23"
},
{
"CatergoryName":"C2S1category2",
"Url" : "www.com23"
}
]
},
{
"SlNo" : 2,
"url" : "www.com1",
"subcategories" : [
{
"CatergoryName":"C2S2category1",
"Url" : "www.com23"
},
{
"CatergoryName":"C2S2category2",
"Url" : "www.com23"
}
]
}
]
}
You need to use $elemMatch to get required output as following:
db.collection.find({
"categories": {
$elemMatch: {
subcategories: {
$elemMatch: {
CatergoryName: "C1S1category1"
}
}
}
}
},{"categories.$":1,"companyName":1,"url":1}).pretty()