AWS Cloudformation list parameter for array type fails - aws-cloudformation

I'm creating a cloudfront distro with cloudformation and trying to use parameters to populate the aliases.
If I use a single string, it fails because it wants a list. And if I use a list, it fails because it wants an array.
For example, this works (no params):
<!-- language: json -->
{
"Resources": {
"FrontEndBucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName":"test.tester.huh"
}
},
"CloudFrontDistro": {
"Type": "AWS::CloudFront::Distribution",
"Properties": {
"DistributionConfig": {
"Aliases": ["testalias.tester.huh"],
"Enabled":true,
"Origins": [
{
"DomainName": "test.tester.huh.s3.amazonaws.com",
"Id":"OriginId",
"S3OriginConfig": { }
}
],
"DefaultCacheBehavior": {
"TargetOriginId": "OriginId",
"ViewerProtocolPolicy": "allow-all",
"ForwardedValues": {
"QueryString": true
}
}
}
}
}
}
}
But when I run this:
{
"Parameters" : {
"DomainAliases" : {
"Type" : "CommaDelimitedList"
}
},
"Resources": {
"CloudFrontDistro": {
"Type": "AWS::CloudFront::Distribution",
"Properties": {
"DistributionConfig": {
"Aliases": {"ref":"DomainAliases"},
"Enabled":true,
"Origins": [
{
"DomainName": "test.tester.huh.s3.amazonaws.com",
"Id":"OriginId",
"S3OriginConfig": { }
}
],
"DefaultCacheBehavior": {
"TargetOriginId": "OriginId",
"ViewerProtocolPolicy": "allow-all",
"ForwardedValues": {
"QueryString": true
}
}
}
}
}
}
}
It fails with this:
(*note: it does pass initial validation)
Property validation failure: [Value of property {/DistributionConfig/Aliases} does not match type {Array}]

Looking at the bare minimum requirements for AWS::CloudFront::Distribution and the sample from their page, the following template validated perfectly fine for me:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"DomainAliases": {
"Type": "CommaDelimitedList"
}
},
"Resources": {
"myDistribution": {
"Type": "AWS::CloudFront::Distribution",
"Properties": {
"DistributionConfig": {
"Aliases": {
"ref": "DomainAliases"
},
"Origins": [{
"DomainName": "mybucket.s3.amazonaws.com",
"Id": "myS3Origin",
"S3OriginConfig": {
"OriginAccessIdentity": "origin-access-identity/cloudfront/E127EXAMPLE51Z"
}
}],
"Enabled": "true",
"DefaultCacheBehavior": {
"AllowedMethods": ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"],
"TargetOriginId": "myS3Origin",
"ForwardedValues": {
"QueryString": "false",
"Cookies": {
"Forward": "none"
}
},
"TrustedSigners": ["1234567890EX", "1234567891EX"],
"ViewerProtocolPolicy": "allow-all"
}
}
}
}
}
}

I ran into this issue myself. It wants Aliases in an array, not a string. Added some square brackets and that fixed it:
"Properties": {
"DistributionConfig":
{
"Aliases":
[
{
"ref":"DomainAliases"
}
],
}
}

Related

Open API 3.0 parameter dependencies: required parameters if type is "one of" (with shared parameters)

I'm creating an openapi.json (version 3.0.3) schema and I'm modelling a post request. The body can look like this:
{
type: "A",
aParam: "string",
sharedParam1: "string",
sharedParam2: "integer",
sharedParam3: "string"
}
where type is one of A or B. If the type is A, the parameter aParam is required if the type is B aParam must be left out. Basically, the other way the request can look is:
{
type: "B",
sharedParam1: "string",
sharedParam2: "integer",
sharedParam3: "string"
}
How can I model this?
Here is what I tried:
{
"requestBody": {
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["A"]
},
"aParam": {
"type": "string"
},
"sharedParam1": {
"type": "string"
},
"sharedParam2": {
"type": "string"
},
"sharedParam3": {
"type": "string"
}
}
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["B"]
},
"sharedParam1": {
"type": "string"
},
"sharedParam2": {
"type": "string"
},
"sharedParam3": {
"type": "string"
}
}
}
]
}
}
}
}
}
Basically, I "overloaded" the request body by using oneOf but that has a lot of duplication.
You may extract the shared properties to a base schema. It won't make the definition much less verbose but at least will remove duplicated properties definitions making them more maintainable:
"components": {
"schemas": {
"baseRequestBody": {
"type": "object",
"required": [
"type",
"sharedParam1",
"sharedParam2",
"sharedParam3"
],
"properties": {
"type": {
"type": "string",
"enum": [
"A",
"B"
]
},
"sharedParam1": {
"type": "string"
},
"sharedParam2": {
"type": "integer"
},
"sharedParam3": {
"type": "string"
}
}
},
"requestBodyA": {
"allOf": [
{
"$ref": "#/components/schemas/baseRequestBody"
},
{
"type": "object",
"required": [
"aParam"
],
"properties": {
"aParam": {
"type": "string"
}
}
}
]
},
"requestBodyB": {
"allOf": [
{
"$ref": "#/components/schemas/baseRequestBody"
}
]
}
}
}
Additionally, you might want to use Discriminator which can be used by some tools like code generators:
"requestBody": {
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/requestBodyA"
},
{
"$ref": "#/components/schemas/requestBodyB"
}
],
"discriminator": {
"propertyName": "type",
"mapping": {
"A": "#/components/schemas/requestBodyA",
"B": "#/components/schemas/requestBodyB"
}
}
}
}
}
}

JOLT - filtering array based on object value

how can I do this?
This is the array....
Can you please help me?
Can you please give me the answer???? Thanks a lot
{
"results": {
"data": [
{
"name": "xx",
"typeRelationship": [
{
"relationship": "parent",
"type": {
"id": "yyyyy",
}
}
],
"id": "xxxxxxxx"
},
{
"name": "yy",
"typeRelationship": [
{
"relationshipType": "parent",
"type": {
"id": "CCCC"
}
},
{
"relationshipType": "child",
"service": {
"id": "DDDD"
}
},
{
"relationshipType": "child",
"service": {
"id": "xxxxxxxx"
}
}
],
"id": "yyyyy"
}
]
}}
expected:
This is expected:
{
"data" : [ {
"id" : "xxxx",
"href" : "xxxxxx",
"relation":"parent"
} ]
}
For some reason I need to type so it does let me update!!!
This works.
[
{
"operation": "shift",
"spec": {
"data": {
"*": {
"type": {
"id": {
"xxxx": {
"#3": "data[]"
}
}
}
}
}
}
}
]
Edit 1
The below spec moves all the values which as id=xxxxx to the data array.
[
{
"operation": "shift",
"spec": {
"data": {
"*": {
"type": {
"*": {
"id": {
"xxxx": {
"#(2)": "data[]",
"#(4,relation)": "data[&3].relation"
}
}
}
}
}
}
}
}
]
This totally works.
Thanks.
Can you please let me know what is 2? 3? 4?
Because my array is a bit different and I want to fix those numbers but does not work....
{
"results": {
"data": [
{
"name": "xx",
"typeRelationship": [
{
"relationship": "parent",
"type": {
"id": "yyyyy",
}
}
],
"id": "xxxxxxxx"
},
{
"name": "yy",
"typeRelationship": [
{
"relationshipType": "parent",
"type": {
"id": "CCCC"
}
},
{
"relationshipType": "child",
"service": {
"id": "DDDD"
}
},
{
"relationshipType": "child",
"service": {
"id": "xxxxxxxx"
}
}
],
"id": "yyyyy"
}
]
}
}
expected:
{
"rows" : [ {
"rowdata" : {
"relationshipType" : "child",
"Name" : "yy",
"id" : "yyyyy"
}
} ]
}

Set null if value is not exists, otherwise return existing value if exists in jolt

As shown in sample input, I have array of extension in each object. When extension doesn't consists subscription-type then output should be null as shown in output or else should consist existing value. Same should be applicable for language-type. Order of subscription-type and language-type is random in nature.
I have tried with spec but its not working
{
"operation": "modify-define-beta",
"spec": {
"*": {
"subscriptionType": {
"url": {
"myCoercedValue": "subscription-type",
"myStringValue": "subscription-type"
},
"value": {
"myCoercedValue": null,
"myStringValue": null
}
},
"languageType": {
"url": {
"myCoercedValue": "language-type",
"myStringValue": "language-type"
},
"value": {
"myCoercedValue": null,
"myStringValue": null
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"extension": "[&1].extension",
"subscriptionType": "[&1].extension[]",
"languageType": "[&1].extension[]"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"extension": {
"*": {
"#url": {
"myStringValue": {
"subscription-type": {
"#(3,value.myStringValue)": "[&3].subscriptionType[]"
}
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"0": "[]"
}
}
]
Input:
[
{
"extension": []
},
{
"extension": [
{
"url": {
"myCoercedValue": "subscription-type",
"myStringValue": "subscription-type"
},
"value": {
"myCoercedValue": "free",
"myStringValue": "free"
},
"extension": []
}
]
},
{
"extension": [
{
"url": {
"myCoercedValue": "language-type",
"myStringValue": "language-type"
},
"value": {
"myCoercedValue": "en-us",
"myStringValue": "en-us"
}
},
{
"url": {
"myCoercedValue": "subscription-type",
"myStringValue": "subscription-type"
},
"value": {
"myCoercedValue": "free",
"myStringValue": "free"
}
}
]
}
]
Output:
[ {
"subscriptionType" : [ null, "free", "free" ],
"language":[null,null,"en-US"]
} ]
Perhaps you want to get such a result? Please, try those spec and say what you want to modify.
[
{
"operation": "shift",
"spec": {
"*": {
"extension": {
"*": {
"url": {
"myCoercedValue": {
"subscription-type": {
"#(3,value)": {
"myCoercedValue": "subscriptionType[#8]"
}
},
"language-type": {
"#(3,value)": {
"myCoercedValue": "language[#8]"
}
}
}
}
}
}
}
}
}
]

Compare and Combine Objects of same array

I want to iterate each object and map system.myStringValue with value.myStringValue
Can you provide spec for the same ?
I have provided the following input and output json. If any other things require form my side , let me know. I have tried with another spec but its not working for me as I want to combine email and phone in one object
Input :
[
{
"telecom": [
{
"system": {
"myStringValue": "email"
},
"value": {
"myStringValue": "mobqa#tester.com"
}
},
{
"system": {
"myStringValue": "phone"
},
"value": {
"myStringValue": "123"
}
}
]
},
{
"telecom": [
{
"system": {
"myStringValue": "email"
},
"value": {
"myStringValue": "john.doe#tester.com"
}
}
]
},
{
"telecom": [
{
"system": {
"myStringValue": "email"
},
"value": {
"myStringValue": "Gayle55#tester.com"
}
}
]
}
]
Output:
{
"users": [
{
"email":"mobqa#tester.com",
"phone":"123"
},
{
"email":"john.doe#tester.com"
},
{
"email":"Gayle55#tester.com"
}
]
}
[
{
"operation": "shift",
"spec": {
"*": {
"telecom": {
"*": {
"value": {
"myStringValue": {
// # takes value of 'value.myStringValue' and puts it into 'users[&5]' occurence
// #(3,system.myStringValue) go up four levels and then go to 'system.myStringValue'
// value and grab it and put as key value to appropriate occurence of 'users'
"#": "users[&5].#(3,system.myStringValue)"
}
}
}
}
}
}
}
]

swagger with list of elements in an array

I am new to swagger implementation. I have a query parameter 'Geschaeftsvorfall' which can be of string value A or P and when I hit the end point. I expect an array[validPsd2Ids] filled with integers.
I have formulated below code and I don't know how to validate it. can someone tell me if I am going wrong some where?
Also what can I do to print a List instead of array in my response?
"parameters": {
"Geschaeftsvorfall": {
"name": "Geschaeftsvorfall",
"in": "query",
"description": "Geschaeftsvorfall",
"required": true,
"type": "string",
"enum": [
"A",
"P"
]
}
},
"definitions": {
"ValidePsd2Ids": {
"type": "array",
"items": {
"properties": {
"ValidePsd2Ids": {
"type": "integer",
example: [100000005,
100000006,
100000007,
100000008,
100000009,
100000010,
100000011,
100000012,
100000013,
100000014,
100000015,
100000016,
100000017,
100000018,
100000019,
100000020,
100000021,
100000022,
100000023,
100000024,
100000025,
100000034,
100000035,
100000036,
100000037,
100000038,
100000039,
100000048,
100000049,
100000050,
100000054,
100000055,
100000056,
100000057,
100000058,
100000117,
100000163,
100000165,
100000195,
100000196,
100000197,
100000198,
100000199,
100000201,
100000214,
100000217,
100000218]
}
}
}
}
},
"paths": {
"/payments/validaccounttypes/": {
"get": {
"tags": [
"payments"
],
"summary": "Valid PSD2 relevant accounts",
"description": "Reads the list of valid PSD2 revelant IDs.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"$ref": "#/parameters/Geschaeftsvorfall"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"properties": {
"ValidePsd2Ids": {
"type": "integer"
}
}
},
"properties": {
"ValidePsd2Ids": {
"$ref": "#/definitions/ValidePsd2Ids"
}
}
}
}
}
}
}
}
The parameter definition is correct.
The response definition is not correct. You say that the response looks like
{"ValidePsd2Ids" : [1,2,3,4,5,6,7,...]}
In OpenAPI terms, this is a type: object with a property ValidePsd2Ids that contains an array of integers. This can be described as:
"definitions": {
"ValidePsd2Ids": {
"type": "object",
"properties": {
"ValidePsd2Ids": {
"type": "array",
"items": {
"type": "integer"
},
"example": [
100000005,
100000006,
100000007
]
}
}
}
},
and the responses should be:
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/ValidePsd2Ids"
}
}
}