How to add section of json to the existing file using jq - bash

I am using jq to parse a JSON file. I have some section of JSON file with below content
[
{
"PropagateAtLaunch": true,
"Value": {
"Ref": "TNAM"
},
"Key": "Name"
},
{
"PropagateAtLaunch": true,
"Value": {
"Ref": "TAPP"
},
"Key": "application"
},
{
"PropagateAtLaunch": true,
"Value": {
"Ref": "TENV"
},
"Key": "environment"
},
{
"PropagateAtLaunch": true,
"Value": {
"Ref": "TSHA"
},
"Key": "shared"
},
{
"PropagateAtLaunch": true,
"Value": {
"Ref": "TTER"
},
"Key": "tier"
},
{
"PropagateAtLaunch": true,
"Value": {
"Ref": "CostCenter"
},
"Key": "cost-center"
}
]
In this I want to add another section like:
{
"Value": {
"Ref": "TEAM"
},
"PropagateAtLaunch": true,
"Key": "TEAM"
}
How can I add this new section?
This is the query I have used to extract the first section:
$ cat ABC.json | jq '.Resources.ASGRP.Properties.Tags'

You can pass the object as a jq variable using --argjson, then use += to add the object to the array:
jq --argjson obj '{"sample": "object"}' '.Resources.ASGRP.Properties.Tags += [$obj]'
If you don't want the original object, use + instead of +=.

Try this "jq -s add ABC.json add.json" as below;
user#host:/tmp$ cat add.json
[
{
"Value": {
"Ref": "TEAM"
},
"PropagateAtLaunch": true,
"Key": "TEAM"
}
]
user#host:/tmp$ jq -s add ABC.json add.json > ABCLAST.json
user#host:/tmp$ cat ABCLAST.json
[
{
"PropagateAtLaunch": true,
"Value": {
"Ref": "TNAM"
},
"Key": "Name"
},
{
"PropagateAtLaunch": true,
"Value": {
"Ref": "TAPP"
},
"Key": "application"
},
{
"PropagateAtLaunch": true,
"Value": {
"Ref": "TENV"
},
"Key": "environment"
},
{
"PropagateAtLaunch": true,
"Value": {
"Ref": "TSHA"
},
"Key": "shared"
},
{
"PropagateAtLaunch": true,
"Value": {
"Ref": "TTER"
},
"Key": "tier"
},
{
"PropagateAtLaunch": true,
"Value": {
"Ref": "CostCenter"
},
"Key": "cost-center"
},
{
"PropagateAtLaunch": true,
"Value": {
"Ref": "TEAM"
},
"Key": "TEAM"
}
]

Related

Get the output of a jq command and iterate over them in a bash script [duplicate]

This question already has answers here:
JQ map objects to array
(4 answers)
Closed 12 days ago.
I have the following json that I need to parse values in a bash script.
{
"matrix-2h44ka21lln62": {
"projectId": "app-54934",
"matrixId": "matrix-2h44ka21lln62",
"state": "FINISHED",
"gcsPath": "App-ios-runner/2023-02-07_13-55-43.444360_CdCC/shard_0",
"webLink": "https://console.firebase.google.com/project/app-54934/testlab/histories/bh.388190097b1eab25/matrices/4663013071689981858/details",
"downloaded": true,
"billableMinutes": {
"virtual": 0,
"physical": 1
},
"clientDetails": {
"Flank Version": "v23.01.0",
"Flank Revision": "7ad3d5ba4097f189965110ca52b93fd0645715e0"
},
"gcsPathWithoutRootBucket": "2023-02-07_13-55-43.444360_CdCC/shard_0",
"gcsRootBucket": "App-ios-runner",
"axes": [
{
"device": "iphone8-15.7-en-portrait",
"outcome": "failure",
"details": "0 test cases failed",
"suiteOverview": {
"total": 0,
"errors": 0,
"failures": 0,
"flakes": 0,
"skipped": 0,
"elapsedTime": 0,
"overheadTime": 0
}
}
],
"appFileName": "App-UISmokeTests.zip",
"testFileName": "App-UISmokeTests_iphoneos16.2-arm64_shard_0.xctestrun",
"isCompleted": false,
"testExecutions": [
{
"id": "matrix-2h44ka21lln62_execution-clgfpxn2zgrta",
"modelId": "iphone8",
"deviceVersion": "15.7",
"state": "FINISHED",
"errorMessage": "",
"progress": [
"Starting attempt 1.",
"Checking Internet connection...",
"Internet connection stable!",
"Starting iOS test.",
"Completed iOS test.",
"Done. Test time = 14 (secs)",
"Starting results processing. Attempt: 1",
"Completed results processing. Time taken = 3 (secs)"
],
"toolResultsStep": {
"executionId": "4663013071689981858",
"historyId": "bh.388190097b1eab25",
"projectId": "app-54934",
"stepId": "bs.2b9b72bccab868fa"
}
}
],
"testTimeout": 2700,
"isRoboTest": false,
"historyId": "",
"executionId": "",
"invalidMatrixDetails": "UNKNOWN",
"outcome": "failure"
},
"matrix-8hj1qx8udleaa": {
"projectId": "app-54934",
"matrixId": "matrix-8hj1qx8udleaa",
"state": "FINISHED",
"gcsPath": "App-ios-runner/2023-02-07_13-55-43.444360_CdCC/shard_1",
"webLink": "https://console.firebase.google.com/project/app-54934/testlab/histories/bh.388190097b1eab25/matrices/5654175129805154564/details",
"downloaded": true,
"billableMinutes": {
"virtual": 0,
"physical": 1
},
"clientDetails": {
"Flank Version": "v23.01.0",
"Flank Revision": "7ad3d5ba4097f189965110ca52b93fd0645715e0"
},
"gcsPathWithoutRootBucket": "2023-02-07_13-55-43.444360_CdCC/shard_1",
"gcsRootBucket": "App-ios-runner",
"axes": [
{
"device": "iphone8-15.7-en-portrait",
"outcome": "failure",
"details": "0 test cases failed",
"suiteOverview": {
"total": 0,
"errors": 0,
"failures": 0,
"flakes": 0,
"skipped": 0,
"elapsedTime": 0,
"overheadTime": 0
}
}
],
"appFileName": "App-UISmokeTests.zip",
"testFileName": "App-UISmokeTests_iphoneos16.2-arm64_shard_1.xctestrun",
"isCompleted": false,
"testExecutions": [
{
"id": "matrix-8hj1qx8udleaa_execution-10jy4hq8i62g4",
"modelId": "iphone8",
"deviceVersion": "15.7",
"state": "FINISHED",
"errorMessage": "",
"progress": [
"Starting attempt 1.",
"Checking Internet connection...",
"Internet connection stable!",
"Starting iOS test.",
"Completed iOS test.",
"Done. Test time = 15 (secs)",
"Starting results processing. Attempt: 1",
"Completed results processing. Time taken = 4 (secs)"
],
"toolResultsStep": {
"executionId": "5654175129805154564",
"historyId": "bh.388190097b1eab25",
"projectId": "app-54934",
"stepId": "bs.b7d2f90beed6230a"
}
}
],
"testTimeout": 2700,
"isRoboTest": false,
"historyId": "",
"executionId": "",
"invalidMatrixDetails": "UNKNOWN",
"outcome": "failure"
},
"matrix-2i6y9uq9i0ext": {
"projectId": "app-54934",
"matrixId": "matrix-2i6y9uq9i0ext",
"state": "FINISHED",
"gcsPath": "App-ios-runner/2023-02-07_13-55-43.444360_CdCC/shard_2",
"webLink": "https://console.firebase.google.com/project/app-54934/testlab/histories/bh.388190097b1eab25/matrices/4958041021718608851/details",
"downloaded": true,
"billableMinutes": {
"virtual": 0,
"physical": 1
},
"clientDetails": {
"Flank Version": "v23.01.0",
"Flank Revision": "7ad3d5ba4097f189965110ca52b93fd0645715e0"
},
"gcsPathWithoutRootBucket": "2023-02-07_13-55-43.444360_CdCC/shard_2",
"gcsRootBucket": "App-ios-runner",
"axes": [
{
"device": "iphone8-15.7-en-portrait",
"outcome": "failure",
"details": "0 test cases failed",
"suiteOverview": {
"total": 0,
"errors": 0,
"failures": 0,
"flakes": 0,
"skipped": 0,
"elapsedTime": 0,
"overheadTime": 0
}
}
],
"appFileName": "App-UISmokeTests.zip",
"testFileName": "App-UISmokeTests_iphoneos16.2-arm64_shard_2.xctestrun",
"isCompleted": false,
"testExecutions": [
{
"id": "matrix-2i6y9uq9i0ext_execution-1zvntyq5awzyv",
"modelId": "iphone8",
"deviceVersion": "15.7",
"state": "FINISHED",
"errorMessage": "",
"progress": [
"Starting attempt 1.",
"Checking Internet connection...",
"Internet connection stable!",
"Starting iOS test.",
"Completed iOS test.",
"Done. Test time = 13 (secs)",
"Starting results processing. Attempt: 1",
"Completed results processing. Time taken = 5 (secs)"
],
"toolResultsStep": {
"executionId": "4958041021718608851",
"historyId": "bh.388190097b1eab25",
"projectId": "app-54934",
"stepId": "bs.283070cfe31b0c"
}
}
],
"testTimeout": 2700,
"isRoboTest": false,
"historyId": "",
"executionId": "",
"invalidMatrixDetails": "UNKNOWN",
"outcome": "failure"
}
}
I went with jq to parse these results but I'm stuck on how to iterate values over the output of my jq command
jq -c --raw-output '.[] | {matrixId: .matrixId, state: .state, details: .axes[].details, device: .axes[].device, webLink: .webLink} | to_entries | map({key:.key, value:.value})'
I want to get the following result
[
{
"key": "matrixId",
"value": "matrix-2h44ka21lln62"
},
{
"key": "state",
"value": "FINISHED"
},
{
"key": "details",
"value": "0 test cases failed"
},
{
"key": "device",
"value": "iphone8-15.7-en-portrait"
},
{
"key": "webLink",
"value": "https://console.firebase.google.com/project/app-54934/testlab/histories/bh.388190097b1eab25/matrices/4663013071689981858/details"
}
],
[
{
"key": "matrixId",
"value": "matrix-8hj1qx8udleaa"
},
{
"key": "state",
"value": "FINISHED"
},
{
"key": "details",
"value": "0 test cases failed"
},
{
"key": "device",
"value": "iphone8-15.7-en-portrait"
},
{
"key": "webLink",
"value": "https://console.firebase.google.com/project/app-54934/testlab/histories/bh.388190097b1eab25/matrices/5654175129805154564/details"
}
],
[
{
"key": "matrixId",
"value": "matrix-2i6y9uq9i0ext"
},
{
"key": "state",
"value": "FINISHED"
},
{
"key": "details",
"value": "0 test cases failed"
},
{
"key": "device",
"value": "iphone8-15.7-en-portrait"
},
{
"key": "webLink",
"value": "https://console.firebase.google.com/project/app-54934/testlab/histories/bh.388190097b1eab25/matrices/4958041021718608851/details"
}
]
It returns the output as three array objects with no comma separated value which is blocking me on iterating over them
I tried to search on how can I join them through piping but it's not working as expected
.[] iterates over the elements in an array and returns a stream of elements. So the input [1,2,3] will be returned as 1 2 3 when filtered through .[].
Now you could stream the array's elements, apply a transformation, and then collect them again: [.[] | f], but hold on. There's a better way: map(f).
Applying this idea to your program gives:
jq -c 'map({matrixId, state, details: .axes[].details, device: .axes[].device, webLink} | to_entries[])'
(Not sure why you have to_entries | map({key:.key, value:.value}), because to_entries already returns objects of that form.)
Output:
[
{
"key": "matrixId",
"value": "matrix-2h44ka21lln62"
},
{
"key": "state",
"value": "FINISHED"
},
{
"key": "details",
"value": "0 test cases failed"
},
{
"key": "device",
"value": "iphone8-15.7-en-portrait"
},
{
"key": "webLink",
"value": "https://console.firebase.google.com/project/app-54934/testlab/histories/bh.388190097b1eab25/matrices/4663013071689981858/details"
},
{
"key": "matrixId",
"value": "matrix-8hj1qx8udleaa"
},
{
"key": "state",
"value": "FINISHED"
},
{
"key": "details",
"value": "0 test cases failed"
},
{
"key": "device",
"value": "iphone8-15.7-en-portrait"
},
{
"key": "webLink",
"value": "https://console.firebase.google.com/project/app-54934/testlab/histories/bh.388190097b1eab25/matrices/5654175129805154564/details"
},
{
"key": "matrixId",
"value": "matrix-2i6y9uq9i0ext"
},
{
"key": "state",
"value": "FINISHED"
},
{
"key": "details",
"value": "0 test cases failed"
},
{
"key": "device",
"value": "iphone8-15.7-en-portrait"
},
{
"key": "webLink",
"value": "https://console.firebase.google.com/project/app-54934/testlab/histories/bh.388190097b1eab25/matrices/4958041021718608851/details"
}
]
If you want an array of arrays, then don't iterate to_entries and simply map to the entries array:
jq 'map({matrixId, state, details: .axes[].details, device: .axes[].device, webLink} | to_entries)'
Output:
[
[
{
"key": "matrixId",
"value": "matrix-2h44ka21lln62"
},
{
"key": "state",
"value": "FINISHED"
},
{
"key": "details",
"value": "0 test cases failed"
},
{
"key": "device",
"value": "iphone8-15.7-en-portrait"
},
{
"key": "webLink",
"value": "https://console.firebase.google.com/project/app-54934/testlab/histories/bh.388190097b1eab25/matrices/4663013071689981858/details"
}
],
[
{
"key": "matrixId",
"value": "matrix-8hj1qx8udleaa"
},
{
"key": "state",
"value": "FINISHED"
},
{
"key": "details",
"value": "0 test cases failed"
},
{
"key": "device",
"value": "iphone8-15.7-en-portrait"
},
{
"key": "webLink",
"value": "https://console.firebase.google.com/project/app-54934/testlab/histories/bh.388190097b1eab25/matrices/5654175129805154564/details"
}
],
[
{
"key": "matrixId",
"value": "matrix-2i6y9uq9i0ext"
},
{
"key": "state",
"value": "FINISHED"
},
{
"key": "details",
"value": "0 test cases failed"
},
{
"key": "device",
"value": "iphone8-15.7-en-portrait"
},
{
"key": "webLink",
"value": "https://console.firebase.google.com/project/app-54934/testlab/histories/bh.388190097b1eab25/matrices/4958041021718608851/details"
}
]
]

How to use filter in map

I have following code:
%dw 2.0 output application/json var attributeIdMapping =
${vault::attributeIdMapping}
--- {
"objectTypeId": 3,
"attributes": vars.requestBody mapObject (value, key) ->
{
"objectTypeAttributeId": (attributeIdMapping.attributes filter ($.name == key))[0].id,
"objectAttributeValues": [{
"value": value,
"key": key
}]
} }
attributeIdMapping:
{
"attributes": [
{
"name": "accountType",
"id": "87"
},
{
"name": "accountClass",
"id": "89"
},
{
"name": "accountName",
"id": "85"
},
{
"name": "displayName",
"id": "18"
},
{
"name": "accountCategory",
"id": "88"
},
{
"name": "accountNumber",
"id": "84"
},
{
"name": "description",
"id": "86"
},
{
"name": "accountGroup",
"id": "90"
}
]
}
vars.requestBody:
{
"displayName": "TestMulesoft2",
"description": "Test"
}
But my filter shows null in the end. As I understand key is not passed to level below map itself. How can I get this working?
I put all the input data inside the script to simplify reproduction. The problem seems to be using the operator == to compare a string and a key types returns empty. Using the operator ~= which attempts to coerce appears to return the expected result:
%dw 2.0
output application/json
var attributeIdMapping =
{
"attributes": [
{
"name": "accountType",
"id": "87"
},
{
"name": "accountClass",
"id": "89"
},
{
"name": "accountName",
"id": "85"
},
{
"name": "displayName",
"id": "18"
},
{
"name": "accountCategory",
"id": "88"
},
{
"name": "accountNumber",
"id": "84"
},
{
"name": "description",
"id": "86"
},
{
"name": "accountGroup",
"id": "90"
}
]
}
var requestBody = {
"displayName": "TestMulesoft2",
"description": "Test"
}
--- {
"objectTypeId": 3,
"attributes": requestBody mapObject (value, key) ->
{
"objectTypeAttributeId": (attributeIdMapping.attributes filter ($.name ~= key))[0].id,
"objectAttributeValues": [{
"value": value,
"key": key
}]
} }
Output:
{
"objectTypeId": 3,
"attributes": {
"objectTypeAttributeId": "18",
"objectAttributeValues": [
{
"value": "TestMulesoft2",
"key": "displayName"
}
],
"objectTypeAttributeId": "86",
"objectAttributeValues": [
{
"value": "Test",
"key": "description"
}
]
}
}

Cloudformation - 'AWS_PROXY' currently only supports Lambda function

I have the following error when I want to create a stack with cloudformation:
The following resource(s) failed to create: [ApiSyncLogsPost]. . Rollback requested by user.
CREATE_FAILED AWS::ApiGateway::Method ApiSyncLogsPost Integrations of type 'AWS_PROXY' currently only supports Lambda function and Firehose stream invocations. (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: 8bff48b0-93e4-11e8-a183-5de2b976f282)
I didn't find anything relevant regarding this error on google, when I search about it I just get a lot of AWS cloudformation documentation.
What I think is happening is that ApiSyncLogsPost resource is not defined properly, but the examples I found on the internet are similar.
What needs to be changed to solve that error?
Here is the cloudformation json:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Metadata": {
"AWS::CloudFormation::Designer": {
"a73e3686-2291-49a2-b052-565c5f85a9c9": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 270,
"y": 120
},
"z": 2,
"parent": "d68e59d4-72c0-425a-9b7b-227cbac3252d",
"embeds": []
},
"0665ec07-964b-4c90-86c5-5f7731cece7b": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 420,
"y": 120
},
"z": 1,
"embeds": []
},
"d68e59d4-72c0-425a-9b7b-227cbac3252d": {
"size": {
"width": 300,
"height": 240
},
"position": {
"x": 60,
"y": 90
},
"z": 1,
"embeds": [
"a73e3686-2291-49a2-b052-565c5f85a9c9",
"2cefafdd-86fd-4cbe-b42e-c638a8c23a19"
],
"iscontainedinside": [
"a86c6b83-5254-4848-943e-db6e35f09bf6"
]
},
"2cefafdd-86fd-4cbe-b42e-c638a8c23a19": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 60,
"y": 120
},
"z": 2,
"parent": "d68e59d4-72c0-425a-9b7b-227cbac3252d",
"embeds": [],
"iscontainedinside": [
"d68e59d4-72c0-425a-9b7b-227cbac3252d",
"d68e59d4-72c0-425a-9b7b-227cbac3252d",
"a86c6b83-5254-4848-943e-db6e35f09bf6"
]
},
"a86c6b83-5254-4848-943e-db6e35f09bf6": {
"size": {
"width": 330,
"height": 330
},
"position": {
"x": 510,
"y": 90
},
"z": 1,
"embeds": [
"66745c5a-f3ad-4b8c-b575-e90d73cbf19b",
"cf340921-6a8b-45f2-8a2a-14ffb0e537e8",
"925587cf-52b3-4507-9131-6be6777905fe"
]
},
"66745c5a-f3ad-4b8c-b575-e90d73cbf19b": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 540,
"y": 150
},
"z": 2,
"parent": "a86c6b83-5254-4848-943e-db6e35f09bf6",
"embeds": [],
"iscontainedinside": [
"a86c6b83-5254-4848-943e-db6e35f09bf6"
]
},
"cf340921-6a8b-45f2-8a2a-14ffb0e537e8": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 680,
"y": 200
},
"z": 2,
"parent": "a86c6b83-5254-4848-943e-db6e35f09bf6",
"embeds": [],
"iscontainedinside": [
"a86c6b83-5254-4848-943e-db6e35f09bf6"
]
},
"925587cf-52b3-4507-9131-6be6777905fe": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 540,
"y": 270
},
"z": 2,
"parent": "a86c6b83-5254-4848-943e-db6e35f09bf6",
"embeds": [],
"iscontainedinside": [
"a86c6b83-5254-4848-943e-db6e35f09bf6"
],
"dependson": [
"2cefafdd-86fd-4cbe-b42e-c638a8c23a19"
]
}
}
},
"Parameters": {
"DatabaseUrl": {
"Description": "DATABASE_URL taken from elastic bean. Example: postgres://my_own_user:my_own_access#my_own_link.rds.amazonaws.com:PORT/my_database_name",
"Type": "String"
},
"LogentriesToken": {
"Description": "",
"Type": "String"
},
"RedisUrl": {
"Description": "",
"Type": "String"
},
"DeploymentStage": {
"Description": "",
"Type": "String",
"Default": "staging"
},
"StackResourcePrefix": {
"Description": "The name will be used to create all the resources that belongs to the same stack.",
"Default": "StagingSyncLogs",
"Type": "String"
}
},
"Resources": {
"ErrorCfn": {
"Type": "AWS::ApiGateway::Model",
"Properties": {
"ContentType": "application/json",
"Name": "ErrorCfn",
"RestApiId": {
"Ref": "SyncLogsApi"
},
"Schema": {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Error Schema",
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "cf340921-6a8b-45f2-8a2a-14ffb0e537e8"
}
}
},
"UserPropertyModel": {
"Type": "AWS::ApiGateway::Model",
"Properties": {
"ContentType": "application/json",
"Name": "UserPropertyModel",
"RestApiId": {
"Ref": "SyncLogsApi"
},
"Schema": {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "UserPropertyModel",
"type": "object",
"properties": {
"Name": {
"type": "string"
}
}
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "66745c5a-f3ad-4b8c-b575-e90d73cbf19b"
}
}
},
"LambdaExecutionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
},
"Path": "/",
"Policies": [
{
"PolicyName": "PolicyNameForLambdaRole",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Sid": "1",
"Effect": "Allow",
"Action": [
"lambda:InvokeFunction"
],
"Resource": [
"*"
]
},
{
"Sid": "2",
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
"*"
]
}
]
}
}
],
"RoleName": {
"Fn::Join": [
"_",
[
{
"Ref": "StackResourcePrefix"
},
"PostgresCron",
"Role"
]
]
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "0665ec07-964b-4c90-86c5-5f7731cece7b"
}
}
},
"SyncLogsLambda": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": "myBucket456464",
"S3Key": "myCode34535.zip"
},
"Environment": {
"Variables": {
"DATABASE_URL": {
"Ref": "DatabaseUrl"
},
"LOGENTRIES_TOKEN": {
"Ref": "LogentriesToken"
},
"REDIS_URL": {
"Ref": "RedisUrl"
}
}
},
"Tags": [
{
"Key": "DeploymentStage",
"Value": {
"Ref": "DeploymentStage"
}
}
],
"FunctionName": {
"Fn::Join": [
"",
[
{
"Ref": "StackResourcePrefix"
},
"_",
"lambda"
]
]
},
"Description": "Lambda function for syncing logs to logentries",
"Handler": "index.handler",
"Runtime": "nodejs6.10",
"MemorySize": 128,
"Timeout": 300,
"Role": {
"Fn::GetAtt": [
"LambdaExecutionRole",
"Arn"
]
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "a73e3686-2291-49a2-b052-565c5f85a9c9"
}
}
},
"ProxyResource": {
"Type": "AWS::ApiGateway::Resource",
"Properties": {
"RestApiId": {
"Ref": "SyncLogsApi"
},
"ParentId": {
"Fn::GetAtt": [
"SyncLogsApi",
"RootResourceId"
]
},
"PathPart": "synclogs"
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "d68e59d4-72c0-425a-9b7b-227cbac3252d"
}
}
},
"SyncLogsApi": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Name": "Sync logs Api",
"Description": "Sync logs when this link is called.",
"FailOnWarnings": true
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "a86c6b83-5254-4848-943e-db6e35f09bf6"
}
}
},
"ApiSyncLogsPost": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"ResourceId": {
"Ref": "ProxyResource"
},
"RestApiId": {
"Ref": "SyncLogsApi"
},
"HttpMethod": "POST",
"AuthorizationType": "NONE",
"Integration": {
"Type": "AWS_PROXY",
"IntegrationHttpMethod": "POST",
"Uri": {
"Fn::Join": [
"",
[
"arn:aws:apigateway:",
{
"Ref": "AWS::Region"
},
":lambda:path/2015-03-31/functions/",
{
"Fn::GetAtt": [
"SyncLogsLambda",
"Arn"
]
},
"/synclogs"
]
]
}
},
"MethodResponses": [
{
"ResponseModels": {
"application/json": {
"Ref": "UserPropertyModel"
}
},
"StatusCode": 200
},
{
"ResponseModels": {
"application/json": {
"Ref": "ErrorCfn"
}
},
"StatusCode": 404
},
{
"ResponseModels": {
"application/json": {
"Ref": "ErrorCfn"
}
},
"StatusCode": 500
}
]
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "2cefafdd-86fd-4cbe-b42e-c638a8c23a19"
}
}
},
"RestApiDeployment": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "SyncLogsApi"
},
"StageName": "Staging"
},
"DependsOn": [
"ApiSyncLogsPost"
],
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "925587cf-52b3-4507-9131-6be6777905fe"
}
}
}
}
}
The error is due to improper value for Integration.Uri in the ApiSyncLogsPost resource. The Uri should have the form:
arn:aws:apigateway:{region}:{subdomain.service|service}:path|action/{service_api}
Example:
arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-1:012345678901:function:MyLambda/invocations
In your case, the string "/synclogs" at the end which should actually be "/invocations"
The following Integration.Uri for ApiSyncLogsPost should fix the issue:
{
"Uri": {
"Fn::Join": [
"",
[
"arn:aws:apigateway:",
{
"Ref": "AWS::Region"
},
":lambda:path/2015-03-31/functions/",
{
"Fn::GetAtt": [
"SyncLogsLambda",
"Arn"
]
},
"/invocations"
]
]
}
}

D3 Json to Hardcoded variables

I want to turn the fetching of data from JSON to a hardcoded variable. This is the link to the d3 treemap chart: Zoomable Treemap Template.
If you mean you want to put JSON data into a variable, then you would represent this:
[
{
"key": "Asia",
"values": [
{
"key": "India",
"value": 1236670000
},
{
"key": "China",
"value": 1361170000
}]
},
{
"key": "Africa",
"values": [
{
"key": "Nigeria",
"value": 173615000
},
{
"key": "Egypt",
"value": 83661000
}]
}
]
like this:
var x = [
{
"key": "Asia",
"values": [
{
"key": "India",
"value": 1236670000
},
{
"key": "China",
"value": 1361170000
}]
},
{
"key": "Africa",
"values": [
{
"key": "Nigeria",
"value": 173615000
},
{
"key": "Egypt",
"value": 83661000
}]
}
];

Kendo UI Grid Column typed date has a trouble

I have a grid which would have many columns typed date. These all grids is generated from a generic function, so that I cannot know whether the column type is date or not. There is one rule validates through all columns. It is that all columns name end with "Date" suffix. For instance, createDate, editDate, visitedDate, etc...
So that, I can understand that it can be date and I parse it like you can see at the dataSource parse function
I have trouble when I update the cell. It does not reflect its own value to Model. The date column proto function returns "Invalid Date" error. I do not understand what it happen
var dataSource = new kendo.data.DataSource({
"data": [
{
"hidden_gridColumns": "",
"id": "21632",
"projectId": "146",
"customerTypeId": "4",
"district": "0",
"fieldSize": "12",
"fieldType": "0",
"floorCoveringType": "12",
"lastChangeDate": null,
"estimatedModificationDate": null,
"latestCompany": ""
}
],
"schema": {
"model": {
"id": "id",
"fields": {
"gridColumns": {
"type": "string"
},
"id": {
"type": "string"
},
"projectId": {
"type": "string"
},
"customerTypeId": {
"type": "string"
},
"district": {
"type": "string"
},
"fieldSize": {
"type": "string"
},
"fieldType": {
"type": "string"
},
"floorCoveringType": {
"type": "string"
},
"lastChangeDate": {
"type": "date"
},
"estimatedModificationDate": {
"type": "string"
},
"latestCompany": {
"type": "string"
}
}
},
parse: function(data){
$.each(data,
function(rowNo,
row){
$.each(row,
function(colName,
column){
if(colName.indexOf("Date")>=0){
console.log(colName + " taranıyor");
row[colName] = kendo.parseDate(row[colName], "dd-MM-yyyy");
}
});
});
return data;
}
},
"batch": true
})
And this is my columns structure:
var columns = [
{
"title": "gridColumns",
"field": "gridColumns",
"hidden": true
},
{
"title": "id",
"field": "id",
"hidden": true
},
{
"title": "projectId",
"field": "projectId",
"hidden": true
},
{
"title": "Müşteri Tipi",
"field": "customerTypeId",
"hidden": false,
"width": "91",
"values": [
{
"value": "1",
"text": "Yurtiçi "
},
{
"value": "2",
"text": "Yurtdışı"
},
{
"value": "3",
"text": "Spor Kulübü"
},
{
"value": "4",
"text": "Diğer"
},
{
"value": "5",
"text": "Üniversite"
},
{
"value": "6",
"text": ""
}
]
},
{
"title": "district",
"field": "district",
"hidden": true,
"width": "132"
},
{
"title": "Saha Ölçüsü",
"field": "fieldSize",
"hidden": false,
"width": "85"
},
{
"title": "Saha Türü",
"field": "fieldType",
"hidden": false,
"values": [
{
"value": "1",
"text": "Açık"
},
{
"value": "0",
"text": "Kapalı"
}
]
},
{
"title": "Halı Cinsi",
"field": "floorCoveringType",
"hidden": false,
"width": "76"
},
{
"title": "Son Halı değişim Tarih",
"field": "lastChangeDate",
"hidden": false,
"format": "{0:dd-MM-yyyy}"
},
{
"title": "Tahmini Yenileme Tarihih",
"field": "estimatedModificationDate",
"hidden": false
},
{
"title": "Son Çalıştığı Halı Firması",
"field": "latestCompany",
"hidden": false
}
]
I solved this problem by the code below:
parse: function(response) {
var tmpData=[];
for (var i = 0; i < response.length; i++) {
var tmpRow = response[i];
$.each(tmpRow, function(colNo, colValue){
if(colNo.indexOf("Date")>-1){
tmpRow[colNo]=kendo.parseDate(new Date(tmpRow[colNo]));
}
});
tmpData.push(tmpRow);
}
return tmpData;
}

Resources