Creating Multiple QueueConfigurations in CloudFormation - json

I'm currently trying to write multiple QueueConfigurations into my CloudFormation template. Each is an SQS queue that is triggered when an object is created to a specified prefix. Here's what I have so far:
{
"Resources": {
"S3Bucket": {
"Type" : "AWS::S3::Bucket",
"Properties" :
"BucketName" : { "Ref" : "paramBucketName" },
"LoggingConfiguration" : {
"DestinationBucketName" : "test-bucket",
"LogFilePrefix" : { "Fn::Join": [ "", [ { "Ref": "paramBucketName" }, "/" ] ] }
},
"NotificationConfiguration" : {
"QueueConfigurations" : [{
"Id" : "1",
"Event" : "s3:ObjectCreated:*",
"Filter" : {
"S3Key" : {
"Rules" : {
"Name" : "prefix",
"Value" : "folder1/"
}
}
},
"Queue" : "arn:aws:sqs:us-east-1:958262988361:interstate-cdc_feeder_prod_hvr_dev"
}],
"QueueConfigurations" : [{
"Id" : "2",
"Event" : "s3:ObjectCreated:*",
"Filter" : {
"S3Key" : {
"Rules" : {
"Name" : "prefix",
"Value" : "folder2/"
}
}
},
"Queue" : "arn:aws:sqs:us-east-1:958262988361:interstate-latency_hvr_dev"
}]
}
}
}
}
}
}
I've encountered the error saying Encountered unsupported property Id. I thought that by defining the ID, I would be able to avoid the Duplicate object key error.
Does anyone know how to create multiple triggers in a single CloudFormation template? Thanks for the help in advance.

It should be structured like the below, There should only be one QueueConfigurations attribute
that contains all queue configurations within it. Also the Id parameter is not a valid property.
{
"Resources": {
"S3Bucket": {
"Type" : "AWS::S3::Bucket",
"Properties" :
"BucketName" : { "Ref" : "paramBucketName" },
"LoggingConfiguration" : {
"DestinationBucketName" : "test-bucket",
"LogFilePrefix" : { "Fn::Join": [ "", [ { "Ref": "paramBucketName" }, "/" ] ] }
},
"NotificationConfiguration" : {
"QueueConfigurations" : [{
"Event" : "s3:ObjectCreated:*",
"Filter" : {
"S3Key" : {
"Rules" : {
"Name" : "prefix",
"Value" : "folder1/"
}
}
},
"Queue" : "arn:aws:sqs:us-east-1:958262988361:interstate-cdc_feeder_prod_hvr_dev"
},
{
"Event" : "s3:ObjectCreated:*",
"Filter" : {
"S3Key" : {
"Rules" : {
"Name" : "prefix",
"Value" : "folder2/"
}
}
},
"Queue" : "arn:aws:sqs:us-east-1:958262988361:interstate-latency_hvr_dev"
}]
}
}
}
}
}
}
There is more information about QueueConfiguration in the documentation.

Related

Nifi: Get values form a Json by a Jsonpath, those were defined in other Json

I have two Json:
Json1:
{
"level_1": [
{
"level_2_1": [
{
"key_2_1": "value_1",
"key_2_2": "value_2",
},
{
"key_2_1": "value_1",
"key_2_3": "value_3",
},
{
"key_2_1": "value_1",
"key_2_4": "value_4",
}
],
"level_2_2": {
"key_2_2_1": "2022-08-30T06:57:31.331Z",
"key_2_2_2": "2022"
}
}
]
}
Json2
{
"level_1" : {
"level_2_1" : {
"value" : "default value",
"type" : "String"
},
"level_2_2" : {
"value" : "level_1[0].level_2_1[0].key_2_2", // this Jsonpath of Json 1
"type" : "String"
},
"level_2_3" : {
"value" : "level_1[0].level_2_2.key_2_2_1", // this Jsonpath of Json 1
"type" : "String"
}
}
I want to get the result like this (these Values come from json1)
{
"level_1" : {
"level_2_1" : {
"value" : "default value",
"type" : "String"
},
"level_2_2" : {
"value" : "value_1", // this Value of Json 1
"type" : "String"
},
"level_2_3" : {
"value" : "2022-08-30T06:57:31.331Z", // this Value of Json 1
"type" : "String"
}
}
please, can you give me some advice. Thank for your help!!

What action to return parsable Json from google to servlet?

I am trying to create a workspace add-on with a couple input boxes and a submit button. The servlet simply returns http endpoints in json code for the google add-on to read the code and build the card properly. However, I cannot seem to figure out how to get the text input values. What action do I need to call on button click to return an http endpoint with parsable json to the servlet?
Here is the code for creating the card:
{"renderActions" : {
"action" : {
"navigations" : [ {
"pushCard" : {
"header" : {
"title" : "NDA Form"
},
"sections" : [ {
"widgets" : [ {
"textParagraph" : {
"text" : "Please check for proper input!"
}
}, {
"textInput" : {
"label" : "Name",
"type" : "SINGLE_LINE",
"name" : "signerName"
}
}, {
"textInput" : {
"label" : "Email",
"type" : "SINGLE_LINE",
"name" : "email"
}
}, {
"textInput" : {
"label" : "Company Name",
"type" : "SINGLE_LINE",
"name" : "compName"
}
}, {
"textInput" : {
"label" : "Address",
"type" : "SINGLE_LINE",
"name" : "address"
}
}, {
"textInput" : {
"label" : "Date",
"type" : "SINGLE_LINE",
"name" : "date"
}
}, {
"buttonList" : {
"buttons" : [ {
"text" : "Submit Form",
"color" : {
"red" : 0.38,
"green" : 0.765,
"blue" : 0.762,
"alpha" : 1.0
},
"onClick" : {
"action" : {
"function" : "https://8f74-38-101-235-211.ngrok.io/landing/process/nda",
"parameters" : [ {
"key" : "action",
"value" : "process/nda"
} ]
}
},
"disabled" : false
} ]
}
} ]
} ]
}
} ]
}}}
And here is a picture of the form on the card:
Card Form

Value of property QueueConfigurations must be of type List

I am trying to write SQS triggers for my S3 bucket. I am running into an error saying "Value of property QueueConfigurations must be of type List." Is there something wrong with my indentation/formatting? Or is it a content error? I recently had to transcribe this from YAML to JSON, and I could really use a second pair of eyes on this issue. Keep in mind that the reason the codeblock below is so indented is because I have some sensitive info I shouldn't post. Thanks in advance!
"NotificationConfiguration" : {
"QueueConfigurations" : {
"Id" : "1",
"Event" : "s3:ObjectCreated:*",
"Filter" : {
"S3Key" : {
"Rules" : {
"Name" : "prefix",
"Value" : "prod_hvr/cdc/"
}
}
},
"Queue" : "arn:aws:sqs:us-east-1:958262988361:interstate-cdc_feeder_prod_hvr_dev"
},
"QueueConfigurations" : {
"Id" : "2",
"Event" : "s3:ObjectCreated:*",
"Filter" : {
"S3Key" : {
"Rules" : {
"Name" : "prefix",
"Value" : "prod_hvr/latency/"
}
}
},
"Queue" : "arn:aws:sqs:us-east-1:958262988361:interstate-latency_hvr_dev"
}
}
It should be something like below. And as per this docs, "Id" is not a valid attribute.
{
"NotificationConfiguration": {
"QueueConfigurations": [
{
"Event": "s3:ObjectCreated:*",
"Filter": {
"S3Key": {
"Rules": {
"Name": "prefix",
"Value": "prod_hvr/cdc/"
}
}
},
"Queue": "arn:aws:sqs:us-east-1:958262988361:interstate-cdc_feeder_prod_hvr_dev"
},
{
"Event": "s3:ObjectCreated:*",
"Filter": {
"S3Key": {
"Rules": {
"Name": "prefix",
"Value": "prod_hvr/latency/"
}
}
},
"Queue": "arn:aws:sqs:us-east-1:958262988361:interstate-latency_hvr_dev"
}
]
}
}

Update deeply nested array in mongodb

I am trying to update field value in mongoose.
{
"_id" : ObjectId("5b62c772efedb6bd3f0c983a"),
"projectID" : ObjectId("0000000050e62416d0d75837"),
"__v" : 0,
"clientID" : ObjectId("00000000996b902b7c3f5efa"),
"inspection_data" : [
{
"pdf" : null,
"published" : "N",
"submissionTime" : ISODate("2018-08-02T08:57:08.532Z"),
"userID" : ObjectId("00000000cac68e3bc04643f7"),
"insSummary" : "inspected areas",
"insName" : "Infotech",
"_id" : ObjectId("5b62c772fa02622a18655e7b"),
"published_date" : ISODate("2018-08-02T08:57:22.041Z"),
"locationAspects" : [
{
"aspectname" : "Ground floor",
"_id" : ObjectId("5b62c772fa02622a18655e80"),
"comments" : [
{
"_id" : ObjectId("5b62c772fa02622a18655e81"),
"images" : [
{
"path" : "/uploads/inspection/00000000996b902b7c3f5efa/images/1533200242005-IpjLKH4XFWNEcHXa.png",
"img_name" : "1533200242005-IpjLKH4XFWNEcHXa.png",
"title" : "Fan",
"id" : "1"
},
{
"path" : "/uploads/inspection/00000000996b902b7c3f5efa/images/1533200242008-YN8IlA5yrMn3cBnn.png",
"img_name" : "1533200242008-YN8IlA5yrMn3cBnn.png",
"title" : "Box",
"id" : "2"
}
],
"comment" : [
"comment4"
],
"recommendation" : ""
}
]
}]
}
Here I want to update a title Fan in image array as table fan.
I tried $set but I don't know how to do for my db structure.
Kindly give some solution to this
**Updated:**
I tried this code:
mongo.inspection.update({"projectID" : mongoose.Types.ObjectId(req.body.project_id) },
{ "$set": {
"inspection_data.$[e1].locationAspects.$[e2].comments.$[e3].images.$[e4].title" : "TableFan"
}},
{ "arrayFilters": [
{ "e1._id": mongoose.Types.ObjectId(req.body.insId)},
{ "e2._id": mongoose.Types.ObjectId(req.body.aspectId)},
{ "e3._id": mongoose.Types.ObjectId(req.body.commentId)},
{ "e4.id": "1" }
]},function(err,response){
if(err){
console.log("error")
}
else{
console.log('Updated')
console.log(response)
}
})
db.adminCommand( { setFeatureCompatibilityVersion: "3.6" } )
Its showing updated but in my db there is no change. Is any mistake I did ?
You can try with arrayFilters in mongodb
var mongoose = require('mongoose')
Temp.update(
{ "_id" : mongoose.Types.ObjectId("5b62c772efedb6bd3f0c983a") },
{ "$set": {
"inspection_data.$[e1].locationAspects.$[e2].comments.$[e3].images.$[e4].title": "TableFan"
}},
{ "arrayFilters": [
{ "e1._id": mongoose.Types.ObjectId("5b62c772fa02622a18655e7b") },
{ "e2._id": mongoose.Types.ObjectId("5b62c772fa02622a18655e80") },
{ "e3._id": mongoose.Types.ObjectId("5b62c772fa02622a18655e81") },
{ "e4.id": "1" }
]}
)
Note: You have to cast _id to ObjectId

Sub-records in Avro with Morphlines

I'm trying to convert JSON into Avro using the kite-sdk morphline module. After playing around I'm able to convert the JSON into Avro using a simple schema (no complex data types).
Then I took it one step further and modified the Avro schema as displayed below (subrec.avsc). As you can see the schema consist of a subrecord.
As soon as I tried to convert the JSON to Avro using the morphlines.conf and the subrec.avsc it failed.
Somehow the JSON paths "/record_type[]/alert/action" are not translated by the toAvro function.
The morphlines.conf
morphlines : [
{
id : morphline1
importCommands : ["org.kitesdk.**"]
commands : [
# Read the JSON blob
{ readJson: {} }
{ logError { format : "record: {}", args : ["#{}"] } }
# Extract JSON
{ extractJsonPaths { flatten: false, paths: {
"/record_type[]/alert/action" : /alert/action,
"/record_type[]/alert/signature_id" : /alert/signature_id,
"/record_type[]/alert/signature" : /alert/signature,
"/record_type[]/alert/category" : /alert/category,
"/record_type[]/alert/severity" : /alert/severity
} } }
{ logError { format : "EXTRACTED THIS : {}", args : ["#{}"] } }
{ extractJsonPaths { flatten: false, paths: {
timestamp : /timestamp,
event_type : /event_type,
source_ip : /src_ip,
source_port : /src_port,
destination_ip : /dest_ip,
destination_port : /dest_port,
protocol : /proto,
} } }
# Create Avro according to schema
{ logError { format : "WE GO TO AVRO"} }
{ toAvro { schemaFile : /etc/flume/conf/conf.empty/subrec.avsc } }
# Create Avro container
{ logError { format : "WE GO TO BINARY"} }
{ writeAvroToByteArray { format: containerlessBinary } }
{ logError { format : "DONE!!!"} }
]
}
]
And the subrec.avsc
{
"type" : "record",
"name" : "Event",
"fields" : [ {
"name" : "timestamp",
"type" : "string"
}, {
"name" : "event_type",
"type" : "string"
}, {
"name" : "source_ip",
"type" : "string"
}, {
"name" : "source_port",
"type" : "int"
}, {
"name" : "destination_ip",
"type" : "string"
}, {
"name" : "destination_port",
"type" : "int"
}, {
"name" : "protocol",
"type" : "string"
}, {
"name": "record_type",
"type" : ["null", {
"name" : "alert",
"type" : "record",
"fields" : [ {
"name" : "action",
"type" : "string"
}, {
"name" : "signature_id",
"type" : "int"
}, {
"name" : "signature",
"type" : "string"
}, {
"name" : "category",
"type" : "string"
}, {
"name" : "severity",
"type" : "int"
}
] } ]
} ]
}
The output on { logError { format : "EXTRACTED THIS : {}", args : ["#{}"] } } I output the following:
[{
/record_type[]/alert / action = [allowed],
/record_type[]/alert / category = [],
/record_type[]/alert / severity = [3],
/record_type[]/alert / signature = [GeoIP from NL,
Netherlands],
/record_type[]/alert / signature_id = [88006],
_attachment_body = [{
"timestamp": "2015-03-23T07:42:01.303046",
"event_type": "alert",
"src_ip": "1.1.1.1",
"src_port": 18192,
"dest_ip": "46.231.41.166",
"dest_port": 62004,
"proto": "TCP",
"alert": {
"action": "allowed",
"gid": "1",
"signature_id": "88006",
"rev": "1",
"signature" : "GeoIP from NL, Netherlands ",
"category" : ""
"severity" : "3"
}
}],
_attachment_mimetype=[json/java + memory],
basename = [simple_eve.json]
}]
UPDATE 2017-06-22
you MUST populate the data in the structure in order for this to work, by using addValues or setValues
{
addValues {
micDefaultHeader : [
{
eventTimestampString : "2017-06-22 18:18:36"
}
]
}
}
after debugging the sources of morphline toAvro, it appears that the record is the first object to be evaluated, no matter what you put in your mappings structure.
the solution is quite simple, but unfortunately took a little extra time, eclipse, running the flume agent in debug mode, cloning the source code and lots of coffee.
here it goes.
my schema:
{
"type" : "record",
"name" : "co_lowbalance_event",
"namespace" : "co.tigo.billing.cboss.lowBalance",
"fields" : [ {
"name" : "dummyValue",
"type" : "string",
"default" : "dummy"
}, {
"name" : "micDefaultHeader",
"type" : {
"type" : "record",
"name" : "mic_default_header_v_1_0",
"namespace" : "com.millicom.schemas.root.struct",
"doc" : "standard millicom header definition",
"fields" : [ {
"name" : "eventTimestampString",
"type" : "string",
"default" : "12345678910"
} ]
}
} ]
}
morphlines file:
morphlines : [
{
id : convertJsonToAvro
importCommands : ["org.kitesdk.**"]
commands : [
{
readJson {
outputClass : java.util.Map
}
}
{
addValues {
micDefaultHeader : [{}]
}
}
{
logDebug { format : "my record: {}", args : ["#{}"] }
}
{
toAvro {
schemaFile : /home/asarubbi/Development/test/co_lowbalance_event.avsc
mappings : {
"micDefaultHeader" : micDefaultHeader
"micDefaultHeader/eventTimestampString" : eventTimestampString
}
}
}
{
writeAvroToByteArray {
format : containerlessJSON
codec : null
}
}
]
}
]
the magic lies here:
{
addValues {
micDefaultHeader : [{}]
}
}
and in the mappings:
mappings : {
"micDefaultHeader" : micDefaultHeader
"micDefaultHeader/eventTimestampString" : eventTimestampString
}
explanation:
inside the code the first field name that is evaluated is micDefaultHeader of type RECORD. as there's no way to specify a default value for a RECORD (logically correct), the toAvro code evaluates this, does not get any value configured in mappings and therefore it fails at it detects (wrongly) that the record is empty when it shouldn't.
however, taking a look at the code, you may see that it requires a Map object, containing no values to please the parser and continue to the next element.
so we add a map object using the addValues and fill it with an empty map [{}]. notice that this must match the name of the record that is causing you an empty value. in my case "micDefaultHeader"
feel free to comment if you have a better solution, as this looks like a "dirty fix"