AWS MediaLive Cloudformation Fn::GetAtt get array value - aws-cloudformation

I am building a Cloudformation template for Media Live I have everything working with the AWS PHP SDK. I create a channel and return the Channels data to be used in the next call.
Return example.
(
[Arn] => arn:aws:mediapackage:us-east-1:000000000000:channels/000000000000
[Description] => Tests
[HlsIngest] => Array
(
[IngestEndpoints] => Array
(
[0] => Array
(
[Id] => 000000000000
[Password] => 000000000000
[Url] => https://000000000000.mediapackage.us-east-1.amazonaws.com/in/v2/1e803c424d2947f58c07d9a6a5ff3d31/000000000000/channel
[Username] => 000000000000
)
[1] => Array
(
[Id] => 000000000000
[Password] => 000000000000
[Url] => https://2bcff136c2fbf1e5.mediapackage.us-east-1.amazonaws.com/in/v2/000000000000/10392b8387fd442eae56f29ac2656837/channel
[Username] => 000000000000
)
)
)
[Id] => sdv
[Tags] => Array
(
)
)
I can then use these values in PHP like this.
$destinationOneUrl = $createChannel['HlsIngest']['IngestEndpoints'][0]['Url'];
Which works but with Cloudformation you have to use the Fn::GetAtt like this.
"Destinations": [{
"Id": "destination1",
"Settings": [{
"Url": {
"Fn::GetAtt": ["MediaPackageChannel", "HlsIngest"]
},
"Username": {
"Fn::GetAtt": ["MediaPackageChannel", "HlsIngest"]
},
"PasswordParam": {
"Fn::GetAtt": ["MediaPackageChannel", "HlsIngest"]
},
},
{
"Url": {
"Fn::GetAtt": ["MediaPackageChannel", "HlsIngest"]
},
"Username": {
"Fn::GetAtt": ["MediaPackageChannel", "HlsIngest"]
},
"PasswordParam": {
"Fn::GetAtt": ["MediaPackageChannel", "HlsIngest"]
},
}
]
}],
You cannot go into the array with this is there another function that can be used in combination with the Fn::GetAtt to get the inner values.
Something along these lines
"Fn::GetAtt": ["MediaPackageChannel", "HlsIngest['IngestEndpoints'][0]['Url']"]
Here is my full template its hard to explain but basically I need to attach my medialive channel to the mediapackage channel as I mention I have done with the php code above Cloudformation doesn't make this easy.
You will see the Destinations section line 39 I need to populate the Url, Username, PasswordParam with the returned values from the mediapackage channel creation.
https://gist.github.com/samueleastdev/03b050f937855a81f36bb1e3260aa5d3

Related

Read JSON in ADF

In Azure Data Factory, I need to be able to process a JSON response. I don't want to hardcode the array position in case they change, so something like this is out of the question:
#activity('Place Details').output.result.components[2].name
How can I get the name 123 where types = number given a JSON array like below:
"result": {
"components": [
{
"name": "ABC",
"types": [
"alphabet"
]
},
{
"name": "123",
"types": [
"number"
]
}
]
}
One example using the OPENJSON method:
DECLARE #json NVARCHAR(MAX) = '{
"result": {
"components": [
{
"name": "ABC",
"types": [
"alphabet"
]
},
{
"name": "123",
"types": [
"number"
]
}
]
}
}'
;WITH cte AS (
SELECT
JSON_VALUE( o.[value], '$.name' ) [name],
JSON_VALUE( o.[value], '$.types[0]' ) [types]
FROM OPENJSON( #json, '$.result.components' ) o
)
SELECT [name]
FROM cte
WHERE types = 'number'
I will have a look at other methods.

PSQL - Query to transpose JSONB element

I have a jsonb object like this:
{
"applicants": [
{
"last_name": "ss",
"first_name": "ss",
"age": 31
},
{
"last_name": "kk",
"first_name": "kk",
"age": 32
}
]
}
I want to convert it to.
{
"applicants": [
{
"last_name": "ss",
"data": {
"first_name": "ss",
"age": 31
}
},
{
"last_name": "kk",
"data": {
"first_name": "kk",
"age": 32
}
}
]
}
I have done a similar thing using jsonb_array_elements and jsonb_build_object before, but I can't figure out how I would create a new data object inside each object, and transpose the fields into it.
Is it possible to write this in plain psql query?
Thanks.
I have to point out that Postgres is not the best tool for modifying JSON data structures, and if you feel the need to do so, it probably means that your solution is in general not optimal. While Postgres has the necessary features to do this, I wouldn't want to maintain code that contains queries like the following.
update my_table set
json_col = (
select
jsonb_build_object(
'applicants',
jsonb_agg(
elem- 'first_name'- 'age' || jsonb_build_object(
'data',
jsonb_build_object(
'first_name',
elem->'first_name',
'age',
elem->'age'
)
)
)
)
from jsonb_array_elements(json_col->'applicants') as arr(elem)
)
Test it in db<>fiddle.

Not Receiving AccessToken on Simulator

My Fulfilment End Point isnt receiving accessToken. Is this normal?
Becouse when im on the simulator it doesnt really ask to login to my authorization end point thus, it wont get a access token. My Oauth is working perfectly after tesing with Oauth Play Ground.
action.json
{
"accountLinking": {
"clientId": "", // SENSITIVE INFORMATION BLANK
"clientSecret": "", // SENSITIVE INFORMATION BLANK
"grantType": "AUTH_CODE",
"authenticationUrl": "", // SENSITIVE INFORMATION BLANK
"accessTokenUrl": "" // SENSITIVE INFORMATION BLANK
},
"actions": [{
"description": "",
"name": "MAIN",
"fulfillment": {
"conversationName": "PASS TEXT"
},
"intent": {
"name": "actions.intent.MAIN",
"trigger": {
"queryPatterns": [
"talk to APP NAME"
]
}
}
}],
"conversations": {
"PASS TEXT": {
"name": "PASS TEXT",
"url": "" // MY FULFILLMENT END POINT
"fulfillmentApiVersion": 2
}
}
}
Fulfilment Received Request
The request was logged into a text file
jsondata = file_get_contents('php://input');
$postdata = json_decode($jsondata, true);
$RAWfile = print_r($postdata, true);
file_put_contents('RAWfile.txt', $RAWfile);
RAWfile.txt
Array
(
[user] => Array
(
[userId] => APhe68HH0PP0nTYnY8jBJed31WqF
[locale] => en-US
)
[conversation] => Array
(
[conversationId] => 1500924702161
[type] => NEW
)
[inputs] => Array
(
[0] => Array
(
[intent] => actions.intent.MAIN
[rawInputs] => Array
(
[0] => Array
(
[inputType] => VOICE
[query] => ask APP NAME to bla bla
)
)
[arguments] => Array
(
[0] => Array
(
[name] => trigger_query
[rawText] => bla bla
[textValue] => bla bla
)
)
)
)
[surface] => Array
(
[capabilities] => Array
(
[0] => Array
(
[name] => actions.capability.AUDIO_OUTPUT
)
)
)
[device] => Array
(
)
[isInSandbox] => 1
)
Simulator Request
{
"query": "bla bla",
"accessToken": "ya29.Gl2TBLrbKjcgK-6jsARmc4Zvkx8qT2X2rE3vsuwEVc_Ey2-q4OUqNWaJPBlXzIjONb_u2MbrE-rgnfwQSZpbZReXsmZjoGOy18Tvp7xzzSJb-cW9SjZ32uLBaKO7vGE",
"expectUserResponse": true,
"conversationToken": "CiZDIzU5O...",
"surface": "GOOGLE_HOME",
"inputType": "VOICE",
"locale": "en-US",
"location": {
"address": "Googleplex, Mountain View, CA, United States",
"position": {
"lat": 37.421980615353675,
"lng": -122.08419799804688
},
"zipCode": "94043",
"city": "Mountain View"
},
"debugInfo": {
"assistantToAgentDebug": {
"assistantToAgentJson": {
"user": {
"userId": "bla",
"locale": "en-US"
},
"conversation": {
"conversationId": "1501004260313",
"type": "NEW"
},
"inputs": [
{
"intent": "actions.intent.MAIN",
"rawInputs": [
{
"inputType": "VOICE",
"query": "bla"
}
],
"arguments": [
{
"name": "trigger_query",
"rawText": "bla",
"textValue": "bla"
}
]
}
],
"surface": {
"capabilities": [
{
"name": "actions.capability.AUDIO_OUTPUT"
}
]
},
"device": {},
"isInSandbox": true
}
}
}
}
Simulator Response
{
"response": "Sure. Here's the test version of bla.\nsure\n",
"conversationToken": "bla",
"audioResponse": "//NExAASS...",
"debugInfo": {
"agentToAssistantDebug": {
"agentToAssistantJson": {
"conversationToken": "{\"state\":null,\"data\":{}}",
"expectUserResponse": false,
"finalResponse": {
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "sure",
"displayText": "sure"
}
}
],
"suggestions": []
}
}
}
}
}
}
Account linking is done through the Actions Console at https://console.actions.google.com/
From the "Overview" menu item, you'll need to get to step 5: Account Linking.
In there, you can set your endpoints, scopes required, etc.
Think you have to manually complete that part - if you look in the response, you'll see a URL - copy/paste and run that, it should complete the account linking process -
https://developers.google.com/actions/identity/account-linking
"In the Log area, copy and paste the URL from the debugInfo.sharedDebugInfo.debugInfo field into your web browser. You will be redirected to the authentication URL for your own server that was specified in API.AI or in the Actions Console."

Yii2 overriding fields() to rename fields in case of validation errors

Ref: http://www.yiiframework.com/doc-2.0/guide-rest-resources.html#overriding-fields
I am overriding fields() to rename fields in User model.
GET - response data fields are renamed as expected
POST - validation error field names are not renamed
1. User table columns
public function rules()
{
return [
[['User_Name', 'Password', 'Auth_Token', 'User_Type_Id', 'User_Status_Id'], 'required'],
]
}
2. overriding fields()
public function fields()
{
return [
'user_id' => 'User_Id',
'access_token' => 'Auth_Token',
'user_name' => 'User_Name',
'user_type' => 'userType.User_Type_Name',
'name' => 'userProfile.Fname',
];
}
3. Get User data (fields renamed as expected)
[
{
"user_id": "1",
"access_token": "123",
"user_name": "kiran",
"user_type": "Customer",
"name": "customer"
}
]
Validate model (error field names are not renamed)
[
{
"field": "User_Name",
"message": "User Name cannot be blank."
},
{
"field": "Password",
"message": "Password cannot be blank."
},
{
"field": "Auth_Token",
"message": "Auth Token cannot be blank."
},
{
"field": "User_Type_Id",
"message": "User Type ID cannot be blank."
},
{
"field": "User_Status_Id",
"message": "User Status ID cannot be blank."
}
]
Using getter/setter methods to load the post data inside user model.
Ref: Yii2 REST create with fields()
Overwriting addError() method to change error field name
public function addError($attribute, $error = '') {
$renamed_attr = $this->renamedFields($attribute);
parent::addError($renamed_attr, $error);
}

Facebook graph query different results in browser and script

When I run the following query https://graph.facebook.com/search?q=Oinoscent&type=place&center=37.973880,23.732035&distance=100&access_token=$AUTHTOKEN in my browser I get the following result back
{
"data": [
{
"category": "Local business",
"category_list": [
{
"id": "192661127431931",
"name": "Wine Bar"
}
],
"location": {
"street": "45-47 Voulis street",
"city": "Athens",
"state": "",
"country": "Greece",
"zip": "10558",
"latitude": 37.974037344191,
"longitude": 23.732089657161
},
"name": "Oinoscent",
"id": "198585923485643"
},
<-- cut here -->
as you can see the name is Oinoscent as we expect and the id is 198585923485643.
If I run the same query inside a php script I get this back
Array
(
[data] => Array
(
[0] => Array
(
[category] => Local business
[category_list] => Array
(
[0] => Array
(
[id] => 2500
[name] => Local Business
)
)
[location] => Array
(
[street] =>
[city] => Athens
[state] =>
[country] => Greece
[zip] =>
[latitude] => 37.9739041863
[longitude] => 23.7320465521
)
[name] => Oinoscent-Wine Bar
[id] => 262001553922414
)
Different Name and different ID though it is exactly the same query. Does anybody know why this is happening?