ElasticSearch indexing issue ,failed to parse timestamp - datetime

i am new to ELK .
i have created index in Elasticsearch
{
"logstash": {
"aliases": {},
"mappings": {
"log": {
"dynamic_templates": [
{
"message_field": {
"path_match": "message",
"match_mapping_type": "string",
"mapping": {
"norms": false,
"type": "text"
}
}
},
{
"string_fields": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"fields": {
"keyword": {
"type": "keyword"
}
},
"norms": false,
"type": "text"
}
}
}
],
"properties": {
"#timestamp": {
"type": "date"
},
"#version": {
"type": "keyword",
"include_in_all": false
},
"activity": {
"type": "text",
"norms": false,
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"beat": {
"properties": {
"hostname": {
"type": "text",
"norms": false,
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"name": {
"type": "text",
"norms": false,
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"version": {
"type": "text",
"norms": false,
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
},
"filename": {
"type": "text",
"norms": false,
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"host": {
"type": "text",
"norms": false,
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"input_type": {
"type": "text",
"norms": false,
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"message": {
"type": "text",
"norms": false
},
"offset": {
"type": "long"
},
"source": {
"type": "text",
"norms": false,
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"tags": {
"type": "text",
"norms": false,
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"timestamp": {
"type": "date",
"include_in_all": false,
"format": "YYYY-MM-DD HH:mm:ss.SSS"
},
"type": {
"type": "text",
"norms": false,
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"user": {
"type": "text",
"norms": false,
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
},
"settings": {
"index": {
"creation_date": "1488805244467",
"number_of_shards": "1",
"number_of_replicas": "0",
"uuid": "5ijhh193Tr6y_hxaQrW9kg",
"version": {
"created": "5020199"
},
"provided_name": "logstash"
}
}
}
}
Below is my logstash configuration
input{
beats{
port=>5044
}
}filter{
grok{
match=>{"message" => "\[%{TIMESTAMP_ISO8601:timestamp}\] ALL AUDIT: User \[%{GREEDYDATA:user}\] is %{GREEDYDATA:activity} \[%{GREEDYDATA:filename}\] for transfer."}
}
}output{
elasticsearch{
hosts=>"localhost:9200"
index=> "logstash"
}
Sample Data
[2017-03-05 12:37:21.465] ALL AUDIT: User [user1] is opening file [filename1] for transfer.
but when i am loading file through filebeat > logstash > elasticsearch
in elasticsearch i am getting below error
org.elasticsearch.index.mapper.MapperParsingException: failed to parse [timestamp]
Caused by: java.lang.IllegalArgumentException: Invalid format: "2017-03-05T12:36:33.606" is malformed at "12:36:33.606"
at org.joda.time.format.DateTimeParserBucket.doParseMillis(DateTimeParserBucket.java:187) ~[joda-time-2.9.5.jar:2.9.5]
Please help , what timestamp format should i configure ?

In your timestamp mapping you indicate the format as "format": "YYYY-MM-DD HH:mm:ss.SSS" Here the format you are sending through beats is not the same, check: 2017-03-05T12:36:33.606
That's why Elastic is complaining about the format. Your format should be: "YYYY-MM-DD'T'HH:mm:ss.SSS" (notice the capital T)
See the documentation for more details: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html

Related

Gatling jsonpath, save value

I have a json response I want to obtain a value from looking like this:
{
"resourceType": "Parameters",
"parameter": [
{
"name": "medication",
"resource": {
"resourceType": "Bundle",
"id": "cfa4fa3c-0e34-431c-ac0d-91653ebda972",
"meta": {
"lastUpdated": "2022-09-23T11:37:49.6022504+02:00",
"source": "http://xxx.xxx/Patient/$getMedication",
"profile": [
"http://xxxStructureDefinition/sfm-MedicationBundle"
]
},
"type": "document",
"timestamp": "2022-09-23T11:37:49.6022471+02:00",
"total": 6,
"link": [
{
"relation": "self",
"url": "http://xxx/Patient/$getMedication"
}
],
"entry": [
{
"fullUrl": "urn:uuid:fbb2bd18-a1c3-4f95-8384-d520fba283a5",
"resource": {
"resourceType": "Composition",
"id": "dfc4f003-4eb6-4802-8b8a-d2d53cf7698c",
"meta": {
"profile": [
"http://xxx/StructureDefinition/sfm-MedicationComposition"
]
},
"identifier": {
"use": "official",
"value": "28c2ae8d-39ed-4054-af46-22bc8c2c1e4a"
},
"status": "final",
"type": {
"coding": [
{
"system": "http://loinc.org",
"code": "11503-0",
"display": "Medical records"
}
]
},
"subject": {
"reference": "urn:uuid:67bb77c3-55dc-4643-b334-7f95e38bcf2f",
"type": "http://xxx/StructureDefinition/sfm-Patient",
"display": "Patient 05129997836"
},
"date": "2022-09-23",
"author": [
{
"reference": "urn:uuid:a443c8b2-a45a-4bad-baa6-f38904363673",
"type": "http://xxx/StructureDefinition/sfm-Practitioner",
"display": "xxx xxx, HPR: xxx"
}
],
"title": "Medication summary",
"confidentiality": "N",
"section": [
{
"title": "Medication",
"code": {
"coding": [
{
"system": "http://xxx/CodeSystem/sfm-section-types",
"code": "sectionMedication",
"display": "List of Medication statements"
}
]
},
"text": {
"status": "generated",
"div": "<xhtml:div xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">List of medications</xhtml:div>"
},
"entry": [
{
"reference": "urn:uuid:8c714f72-0c90-403d-9e80-b08c61f82068",
"type": "http://xxx/fhir/StructureDefinition/sfm-MedicationStatement",
"display": "Paracetamol tab 1 g"
}
]
},
{
"title": "PllInfo",
"code": {
"coding": [
{
"system": "http://xxx/fhir/CodeSystem/sfm-section-types",
"code": "sectionPLLinfo",
"display": "PLL Info"
}
]
},
"text": {
"status": "generated",
"div": "<xhtml:div xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">Nil Known</xhtml:div>"
},
"emptyReason": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/list-empty-reason",
"code": "nilknown",
"display": "Nil Known"
}
],
"text": "Nil Known"
}
},
{
"title": "Allergies",
"code": {
"coding": [
{
"system": "http://xxx/fhir/CodeSystem/sfm-section-types",
"code": "sectionAllergies",
"display": "Section allergies"
}
]
},
"text": {
"status": "generated",
"div": "<xhtml:div xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">Nil Known</xhtml:div>"
},
"emptyReason": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/list-empty-reason",
"code": "nilknown",
"display": "Nil Known"
}
],
"text": "Nil Known"
}
},
{
"title": "Other Prescriptions",
"code": {
"coding": [
{
"system": "http://xxx/fhir/CodeSystem/sfm-section-types",
"code": "sectionOtherPrescriptions",
"display": "List of non medical prescriptions"
}
]
},
"text": {
"status": "generated",
"div": "<xhtml:div xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">Nil Known</xhtml:div>"
},
"emptyReason": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/list-empty-reason",
"code": "nilknown",
"display": "Nil Known"
}
],
"text": "Nil Known"
}
}
]
}
},
{
"fullUrl": "urn:uuid:a443c8b2-a45a-4bad-baa6-f38904363673",
"resource": {
"resourceType": "Practitioner",
"id": "1571880245",
"meta": {
"profile": [
"http://xxx/fhir/StructureDefinition/sfm-Practitioner"
]
},
"identifier": [
{
"use": "official",
"type": {
"coding": [
{
"system": "http://hl7.no/fhir/NamingSystem/HPR",
"code": "HPR-nummer"
}
]
},
"system": "urn:oid:2.16.578.1.12.4.1.4.4",
"value": "10055817"
},
{
"use": "official",
"type": {
"coding": [
{
"system": "http://hl7.no/fhir/NamingSystem/FNR",
"code": "FNR-nummer"
}
]
},
"system": "urn:oid:2.16.578.1.12.4.1.4.1",
"value": "10099205569"
}
],
"active": true,
"name": [
{
"use": "official",
"family": "xxx",
"given": [
"xxx"
]
}
],
"gender": "male",
"birthDate": "1992-09-10"
}
},
{
"fullUrl": "urn:uuid:67bb77c3-55dc-4643-b334-7f95e38bcf2f",
"resource": {
"resourceType": "Patient",
"id": "873788333",
"meta": {
"profile": [
"http://xxx/fhir/StructureDefinition/sfm-Patient"
]
},
"identifier": [
{
"use": "official",
"type": {
"coding": [
{
"system": "http://hl7.no/fhir/NamingSystem/FNR",
"code": "FNR-nummer"
}
]
},
"system": "urn:oid:2.16.578.1.12.4.1.4.1",
"value": "05129997836"
}
],
"active": true,
"name": [
{
"family": "05129997836",
"given": [
"Patient"
]
}
],
"gender": "female",
"birthDate": "1999-12-05",
"address": [
{
"type": "postal",
"text": "Autoveien 1",
"city": "Oslo",
"postalCode": "0150"
}
]
}
},
{
"fullUrl": "urn:uuid:f4c95e15-8e9f-416a-83c7-3a6847d69278",
"resource": {
"resourceType": "Practitioner",
"id": "1215535826",
"meta": {
"profile": [
"http://xxx/fhir/StructureDefinition/sfm-Practitioner"
]
},
"identifier": [
{
"use": "official",
"type": {
"coding": [
{
"system": "http://hl7.no/fhir/NamingSystem/HPR",
"code": "HPR-nummer"
}
]
},
"system": "urn:oid:2.16.578.1.12.4.1.4.4",
"value": "1010038"
}
],
"active": true,
"name": [
{
"extension": [
{
"url": "http://hl7.no/fhir/StructureDefinition/no-basis-middlename",
"valueString": "Psa"
}
],
"use": "official",
"family": "xx",
"given": [
"xx"
]
}
],
"gender": "male"
}
},
{
"fullUrl": "urn:uuid:4b4de0ae-3f2d-4030-a193-26713cf30260",
"resource": {
"resourceType": "Medication",
"id": "667718723",
"meta": {
"profile": [
"http://xxx/fhir/StructureDefinition/sfm-Medication"
]
},
"extension": [
{
"extension": [
{
"url": "prescriptiongroup",
"valueCodeableConcept": {
"coding": [
{
"system": "urn:oid:2.16.578.1.12.4.1.1.7421",
"code": "C",
"display": "Reseptgruppe C"
}
]
}
}
],
"url": "http://hl7.no/fhir/StructureDefinition/no-basis-prescriptiongroup"
},
{
"extension": [
{
"url": "registreringstype",
"valueCodeableConcept": {
"coding": [
{
"system": "http://xxx/fhir/CodeSystem/sfm-festregistrationtype",
"code": "1",
"display": "Legemiddelvirkestoff"
}
]
}
}
],
"url": "http://xxx/fhir/StructureDefinition/sfm-medicationdetails"
}
],
"identifier": [
{
"use": "official",
"type": {
"text": "identifier"
},
"value": "ID_DF40453A-DAD1-450D-A58D-0FE411DCDB05"
}
],
"code": {
"coding": [
{
"system": "http://xxx/fhir/CodeSystem/FEST",
"code": "ID_DF40453A-DAD1-450D-A58D-0FE411DCDB05",
"display": "Paracetamol tab 1 g"
},
{
"system": "http://www.whocc.no/atc",
"code": "N02BE01",
"display": "Paracetamol"
}
]
},
"status": "active",
"form": {
"coding": [
{
"system": "urn:oid:2.16.578.1.12.4.1.1.7448",
"code": "53",
"display": "Tablett"
}
]
}
}
},
{
"fullUrl": "urn:uuid:8c714f72-0c90-403d-9e80-b08c61f82068",
"resource": {
"resourceType": "MedicationStatement",
"id": "1850837775",
"meta": {
"profile": [
"http://xxx/fhir/StructureDefinition/sfm-MedicationStatement"
]
},
"extension": [
{
"extension": [
{
"url": "reseptdate",
"valueDate": "2022-09-21"
},
{
"url": "expirationdate",
"valueDate": "2023-09-20"
},
{
"url": "festUpdate",
"valueDateTime": "2022-08-25T13:54:02+00:00"
},
{
"url": "dssn",
"valueString": "1 tablett morgen daglig"
},
{
"url": "amount",
"valueQuantity": {
"value": 92.0,
"unit": "stk"
}
},
{
"url": "reit",
"valueString": "3"
},
{
"url": "itemgroup",
"valueCodeableConcept": {
"coding": [
{
"system": "urn:oid:2.16.578.1.12.4.1.1.7402",
"code": "L",
"display": "Legemiddel"
}
]
}
},
{
"extension": [
{
"url": "starttime",
"valueDate": "2022-09-21"
},
{
"extension": [
{
"url": "amount",
"valueQuantity": {
"value": 1.0,
"unit": "tablett"
}
},
{
"url": "interval",
"valueQuantity": {
"value": 1.0,
"unit": "Døgn"
}
},
{
"url": "accurate",
"valueBoolean": false
},
{
"url": "timerange",
"valueCodeableConcept": {
"coding": [
{
"system": "urn:oid:2.16.578.1.12.4.1.1.8325",
"code": "1",
"display": "Morgen"
}
]
}
}
],
"url": "repeatingdosage"
}
],
"url": "ereseptdosing"
},
{
"extension": [
{
"url": "status",
"valueCodeableConcept": {
"coding": [
{
"system": "urn:oid:2.16.578.1.12.4.1.1.7408",
"code": "E",
"display": "Ekspederbar"
}
]
}
}
],
"url": "rfstatus"
},
{
"url": "typeresept",
"valueCodeableConcept": {
"coding": [
{
"system": "urn:oid:2.16.578.1.12.4.1.1.7491",
"code": "E",
"display": "Eresept"
}
]
}
}
],
"url": "http://xxx/fhir/StructureDefinition/sfm-reseptamendment"
},
{
"extension": [
{
"url": "status",
"valueCodeableConcept": {
"coding": [
{
"system": "http://xxx/fhir/CodeSystem/sfm-medicationstatement-registration-status",
"code": "3",
"display": "Godkjent"
}
]
}
},
{
"url": "type",
"valueCodeableConcept": {
"coding": [
{
"system": "http://xxx/fhir/CodeSystem/sfm-performer-roles",
"code": "1",
"display": "Forskrevet av"
}
]
}
},
{
"url": "provider",
"valueReference": {
"reference": "urn:uuid:f4c95e15-8e9f-416a-83c7-3a6847d69278",
"type": "http://xxx/fhir/StructureDefinition/sfm-Practitioner",
"display": "Bjørn Psa Visjon, HPR: 1010038"
}
},
{
"url": "timestamp",
"valueDateTime": "2022-09-21T16:10:25.5229768+02:00"
}
],
"url": "http://xxx/fhir/StructureDefinition/sfm-regInfo"
},
{
"extension": [
{
"url": "genericSubstitutionAccepted",
"valueBoolean": true
}
],
"url": "http://xxx/fhir/StructureDefinition/sfm-generic-substitution"
},
{
"extension": [
{
"url": "nocombination",
"valueBoolean": false
}
],
"url": "http://xxx/fhir/StructureDefinition/sfm-administration"
}
],
"identifier": [
{
"use": "usual",
"type": {
"text": "ReseptId"
},
"value": "1dfa55d7-674d-4fc8-a182-1fbd3b2faa6a"
}
],
"status": "active",
"medicationReference": {
"reference": "urn:uuid:4b4de0ae-3f2d-4030-a193-26713cf30260",
"type": "http://xxx/fhir/StructureDefinition/sfm-Medication",
"display": "Paracetamol tab 1 g"
},
"subject": {
"reference": "urn:uuid:67bb77c3-55dc-4643-b334-7f95e38bcf2f",
"type": "http://xxx/fhir/StructureDefinition/sfm-Patient",
"display": "Patient 05129997836"
},
"dosage": [
{
"extension": [
{
"url": "http://xxx/fhir/StructureDefinition/sfm-use",
"valueCodeableConcept": {
"coding": [
{
"system": "urn:oid:2.16.578.1.12.4.1.1.9101",
"code": "1",
"display": "Fast"
}
]
}
},
{
"extension": [
{
"url": "text",
"valueString": "MOT SMERTER"
}
],
"url": "http://xxx/fhir/StructureDefinition/sfm-application-area"
}
],
"sequence": 1,
"text": "1 tablett morgen daglig"
}
]
}
}
]
}
},
{
"name": "KJHentetTidspunkt",
"valueDateTime": "2022-09-23T09:37:49.55+00:00"
},
{
"name": "RFHentetTidspunkt",
"valueDateTime": "2022-09-23T11:37:49.027+02:00"
},
{
"name": "KJFeilkode",
"valueCodeableConcept": {
"coding": [
{
"system": "http://xxx/fhir/CodeSystem/sfm-kj-rf-error-code",
"code": "0"
}
],
"text": "OK"
}
},
{
"name": "RFM96Feilkode",
"valueCodeableConcept": {
"coding": [
{
"system": "http://xxx/fhir/CodeSystem/sfm-kj-rf-error-code",
"code": "0"
}
],
"text": "OK"
}
},
{
"name": "RFM912Feilkode",
"valueCodeableConcept": {
"coding": [
{
"system": "http://xxx/fhir/CodeSystem/sfm-kj-rf-error-code",
"code": "0"
}
],
"text": "OK"
}
},
{
"name": "KJHarLegemidler",
"valueBoolean": false
},
{
"name": "KJHarLaste",
"valueBoolean": false
},
{
"name": "RFHarLaste",
"valueBoolean": false
}
]
}
The value I am looking for is the "fullUrl", as in urn:uuid:fbb2bd18-a1c3-4f95-8384-d520fba283a5
I tried to use this jsonpath expression:
.check(jsonPath("$..[?(#.resourceType=="Bundle")].entry.fullUrl").saveAs("fullUrl"))
However it says
jsonPath($..[?(#.resourceType=="Bundle")].entry.fullUrl).find. exists, found nothing
How can I construct an experssion to obtain the fullUrl?
It's because entry is array. So you have two options how to extract the value.
You can get all fullUrl values and then obtain via Gatling EL:
jsonPath("$..[?(#.resourceType=='Bundle')].entry..fullUrl").findAll.saveAs("fullUrls")
And then just get by index #{fullUrls(0)} (Documentation)
Or get by index in the json path:
|
|
ᐯ
jsonPath("$..[?(#.resourceType=='Bundle')].entry.[0].fullUrl").findAll.saveAs("fullUrl")

Can I get the user email within a Velocity template of AWS Amplify?

When I query a resolver in my GraphQL API, in which I have added a $util.error($ctx) to return the context object, I get the following result (removed unnecessary values).
{
"data": {
"listXData": null
},
"errors": [
{
"message": {
"arguments": {},
"args": {},
"info": {
"fieldName": "listXData",
"variables": {},
"parentTypeName": "Query",
"selectionSetList": [
"items",
"items/id",
"items/createdAt",
"items/updatedAt",
"nextToken"
],
"selectionSetGraphQL": "{\n items {\n id\n createdAt\n updatedAt\n }\n nextToken\n}"
},
"request": {...},
"identity": {
"sub": "",
"issuer": "",
"username": "013fe9d2-95f7-4885-83ec-b7e2e0a1423f",
"sourceIp": "",
"claims": {
"origin_jti": "",
"sub": "",
"event_id": "",
"token_use": "",
"scope": "",
"auth_time": ,
"iss": "",
"exp": ,
"iat": ,
"jti": "",
"client_id": "",
"username": "013fe9d2-95f7-4885-83ec-b7e2e0a1423f"
},
"defaultAuthStrategy": "ALLOW"
},
"stash": {},
"source": null,
"result": {
"items": [],
"scannedCount": 0,
"nextToken": null
},
"error": null,
"prev": {
"result": {}
}
},
"errorType": null,
"data": null,
"errorInfo": null,
"path": [
"listXData"
],
"locations": [
{
"line": 2,
"column": 3,
"sourceName": "GraphQL request"
}
]
}
]
}
As you can see, the username is an ID, however I would prefer to (also) have the email. Is it possible to get the user email (within the Velocity template)?
Let me know if I need to add more details or if my question is unclear.
The identity context only returns back the Cognito username for the user pool. You will need to setup pipeline functions to perform additional queries to get your user information. Here is one intro to setting them up.
At this point, it seems that it is not possible to do this purely by vtl.
I have implemented it using a lambda function, as follow:
Lambda function (node):
/* Amplify Params - DO NOT EDIT
ENV
REGION
Amplify Params - DO NOT EDIT */
const aws = require('aws-sdk')
const cognitoidentityserviceprovider = new aws.CognitoIdentityServiceProvider({
apiVersion: '2016-04-18',
region: 'eu-west-1'
})
exports.handler = async (context, event, callback) => {
if (!context.identity?.username) {
callback('Not signed in')
}
const params = {
'AccessToken': context.request.headers.authorization
}
const result = await cognitoidentityserviceprovider.getUser(params).promise()
const email = result.UserAttributes.find(attribute => attribute.Name === 'email')
callback(null, JSON.stringify({ email }))
}
CustomResources.json
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "An auto-generated nested stack.",
"Metadata": {...},
"Parameters": {...},
"Resources": {
"GetEmailLambdaDataSourceRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"RoleName": {
"Fn::If": [
"HasEnvironmentParameter",
{
"Fn::Join": [
"-",
[
"GetEmail17ec",
{
"Ref": "GetAttGraphQLAPIApiId"
},
{
"Ref": "env"
}
]
]
},
{
"Fn::Join": [
"-",
[
"GetEmail17ec",
{
"Ref": "GetAttGraphQLAPIApiId"
}
]
]
}
]
},
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "appsync.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
},
"Policies": [
{
"PolicyName": "InvokeLambdaFunction",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"lambda:InvokeFunction"
],
"Resource": {
"Fn::If": [
"HasEnvironmentParameter",
{
"Fn::Sub": [
"arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:GetEmail-${env}",
{
"env": {
"Ref": "env"
}
}
]
},
{
"Fn::Sub": [
"arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:GetEmail",
{}
]
}
]
}
}
]
}
}
]
}
},
"GetEmailLambdaDataSource": {
"Type": "AWS::AppSync::DataSource",
"Properties": {
"ApiId": {
"Ref": "AppSyncApiId"
},
"Name": "GetEmailLambdaDataSource",
"Type": "AWS_LAMBDA",
"ServiceRoleArn": {
"Fn::GetAtt": [
"GetEmailLambdaDataSourceRole",
"Arn"
]
},
"LambdaConfig": {
"LambdaFunctionArn": {
"Fn::If": [
"HasEnvironmentParameter",
{
"Fn::Sub": [
"arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:GetEmail-${env}",
{
"env": {
"Ref": "env"
}
}
]
},
{
"Fn::Sub": [
"arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:GetEmail",
{}
]
}
]
}
}
},
"DependsOn": "GetEmailLambdaDataSourceRole"
},
"InvokeGetEmailLambdaDataSource": {
"Type": "AWS::AppSync::FunctionConfiguration",
"Properties": {
"ApiId": {
"Ref": "AppSyncApiId"
},
"Name": "InvokeGetEmailLambdaDataSource",
"DataSourceName": "GetEmailLambdaDataSource",
"FunctionVersion": "2018-05-29",
"RequestMappingTemplateS3Location": {
"Fn::Sub": [
"s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/pipelineFunctions/${ResolverFileName}",
{
"S3DeploymentBucket": {
"Ref": "S3DeploymentBucket"
},
"S3DeploymentRootKey": {
"Ref": "S3DeploymentRootKey"
},
"ResolverFileName": {
"Fn::Join": [
".",
[
"InvokeGetEmailLambdaDataSource",
"req",
"vtl"
]
]
}
}
]
},
"ResponseMappingTemplateS3Location": {
"Fn::Sub": [
"s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/pipelineFunctions/${ResolverFileName}",
{
"S3DeploymentBucket": {
"Ref": "S3DeploymentBucket"
},
"S3DeploymentRootKey": {
"Ref": "S3DeploymentRootKey"
},
"ResolverFileName": {
"Fn::Join": [
".",
[
"InvokeGetEmailLambdaDataSource",
"res",
"vtl"
]
]
}
}
]
}
},
"DependsOn": "GetEmailLambdaDataSource"
},
"IsOrganizationMember": {
"Type": "AWS::AppSync::FunctionConfiguration",
"Properties": {
"FunctionVersion": "2018-05-29",
"ApiId": {
"Ref": "AppSyncApiId"
},
"Name": "IsOrganizationMember",
"DataSourceName": "PermissionsPerOrganizationTable",
"RequestMappingTemplateS3Location": {
"Fn::Sub": [
"s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/Query.isOrganizationMember.req.vtl",
{
"S3DeploymentBucket": {
"Ref": "S3DeploymentBucket"
},
"S3DeploymentRootKey": {
"Ref": "S3DeploymentRootKey"
}
}
]
},
"ResponseMappingTemplateS3Location": {
"Fn::Sub": [
"s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/Query.isOrganizationMember.res.vtl",
{
"S3DeploymentBucket": {
"Ref": "S3DeploymentBucket"
},
"S3DeploymentRootKey": {
"Ref": "S3DeploymentRootKey"
}
}
]
}
}
},
"OrganizationAccessPipeline": {
"Type": "AWS::AppSync::Resolver",
"Properties": {
"ApiId": {
"Ref": "AppSyncApiId"
},
"TypeName": "Query",
"Kind": "PIPELINE",
"FieldName": "listXData",
"PipelineConfig": {
"Functions": [
{
"Fn::GetAtt": [
"InvokeGetEmailLambdaDataSource",
"FunctionId"
]
},
{
"Fn::GetAtt": [
"IsOrganizationMember",
"FunctionId"
]
}
]
},
"RequestMappingTemplate": "{}",
"ResponseMappingTemplate": "$util.toJson($ctx.result)"
}
}
},
"Conditions": {...},
"Outputs": {...}
}
The lambda is created with the CLI and IsOrganizationMember is a regular VTL which has the user email in the $context.prev.result.

How can I create a Pydantic Model for my FastAPI endpoint when my JSON is something like this?

{
'events': [
{
'type': 'message',
'replyToken': '0bc647fc5282423cde13fffbc947a8',
'source': {
'userId': 'U996ed69353d3c962ee17b33d9af3e2',
'type': 'user'
},
'timestamp': 161185209914,
'mode': 'active',
'message': {
'type': 'text',
'id': '1346188304367',
'text': ' hello'
}
}
],
'destination': 'Uf44eb3ba6c4b87adbfaa4a517e'
}
this is the json from the webhook I'm using
it's contained like this, how can I write a Pytantic model for it?
This should work fine with the request body you given above.
from pydantic import BaseModel
from typing import List
class Source(BaseModel):
userId: str
type: str
class Message(BaseModel):
type: str
id: str
text: str
class Event(BaseModel):
type: str
replyToken: str
source: Source
timestamp: int
mode: str
message: Message
class Webhook(BaseModel):
events: List[Event]
destination: str
Here is the OpenAPI schema for Webhook model.
{
"title": "Webhook",
"type": "object",
"properties": {
"events": {
"title": "Events",
"type": "array",
"items": {
"$ref": "#/definitions/Event"
}
},
"destination": {
"title": "Destination",
"type": "string"
}
},
"required": [
"events",
"destination"
],
"definitions": {
"Source": {
"title": "Source",
"type": "object",
"properties": {
"userId": {
"title": "Userid",
"type": "string"
},
"type": {
"title": "Type",
"type": "string"
}
},
"required": [
"userId",
"type"
]
},
"Message": {
"title": "Message",
"type": "object",
"properties": {
"type": {
"title": "Type",
"type": "string"
},
"id": {
"title": "Id",
"type": "string"
},
"text": {
"title": "Text",
"type": "string"
}
},
"required": [
"type",
"id",
"text"
]
},
"Event": {
"title": "Event",
"type": "object",
"properties": {
"type": {
"title": "Type",
"type": "string"
},
"replyToken": {
"title": "Replytoken",
"type": "string"
},
"source": {
"$ref": "#/definitions/Source"
},
"timestamp": {
"title": "Timestamp",
"type": "integer"
},
"mode": {
"title": "Mode",
"type": "string"
},
"message": {
"$ref": "#/definitions/Message"
}
},
"required": [
"type",
"replyToken",
"source",
"timestamp",
"mode",
"message"
]
}
}
}

How do I pass RegistrationKey to Azure DSC extenstion

I have template below which errors out during deployment with error below. Samples on documentation page seems to be erroneous and don't even compile.
"message": "VM has reported a failure when processing extension
'Microsoft.Powershell.DSC'. Error message: \"The DSC Extension failed
to install: Invalid type for parameter RegistrationKey of type
PSCredential.\nMore information about the failure can be found in the
logs located under
'C:\WindowsAzure\Logs\Plugins\Microsoft.Powershell.DSC\2.74.0.0'
on the VM.\nTo retry install, please remove the extension from the VM
first. \"."
Template
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"name": "[parameters('swarmmanager1Name')]",
"type": "Microsoft.Compute/virtualMachines",
"location": "[resourceGroup().location]",
"apiVersion": "2015-06-15",
"tags": {
"displayName": "swarmmanager1"
},
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('swarmmanager1VmSize')]"
},
"licenseType": "[parameters('LicenseType')]",
"osProfile": {
"computerName": "[parameters('swarmmanager1Name')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"publisher": "[parameters('swarmmanager1ImagePublisher')]",
"offer": "[parameters('swarmmanager1ImageOffer')]",
"sku": "[parameters('windowsOSVersion')]",
"version": "latest"
},
"osDisk": {
"name": "swarmmanager1OSDisk",
"vhd": {
"uri": "[concat(reference(resourceId('Microsoft.Storage/storageAccounts', parameters('dockerswarmstorageaccountName')), '2016-01-01').primaryEndpoints.blob, parameters('swarmmanager1StorageAccountContainerName'), '/', parameters('swarmmanager1OSDiskName'), '.vhd')]"
},
"caching": "ReadWrite",
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('swarmmanager1NicName'))]"
}
]
}
},
"resources": [
{
"name": "Microsoft.Powershell.DSC",
"type": "extensions",
"location": "[resourceGroup().location]",
"apiVersion": "2015-06-15",
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', parameters('swarmmanager1Name'))]"
],
"tags": {
"displayName": "DSC"
},
"properties": {
"publisher": "Microsoft.Powershell",
"typeHandlerVersion": "2.26",
"type": "DSC",
"autoUpgradeMinorVersion": true,
"forceUpdateTag": "[parameters('DSCExtensionManagerTagVersion')]",
"settings": {
"wmfVersion": "latest",
"configurationArguments": {
//"RegistrationKey": {
// "UserName": "PLACEHOLDER_DONOTUSE",
// "Password": "PrivateSettingsRef:registrationKeyPrivate"
// },
"RegistrationKey": "[parameters('RegistrationKey')]",
"RegistrationUrl": "[parameters('registrationUrl')]",
"NodeConfigurationName": "SwarmManager.localhost",
"RebootNodeIfNeeded": true
}
},
"protectedSettings": {
"Items": {
"registrationKeyPrivate": "[parameters('RegistrationKey')]"
}
}
}
}
]
},
{
"name": "[parameters('dockerswarmstorageaccountName')]",
"type": "Microsoft.Storage/storageAccounts",
"location": "[resourceGroup().location]",
"apiVersion": "2016-01-01",
"sku": {
"name": "[parameters('dockerswarmstorageaccountType')]"
},
"dependsOn": [],
"tags": {
"displayName": "dockerswarmstorageaccount"
},
"kind": "Storage"
},
{
"name": "[parameters('swarmmanager1NicName')]",
"type": "Microsoft.Network/networkInterfaces",
"location": "[resourceGroup().location]",
"apiVersion": "2016-03-30",
"tags": {
"displayName": "swarmmanager1Nic"
},
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[parameters('swarmmanager1SubnetRef')]"
},
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('swarmmanagerpublicIPName'))]"
}
}
}
]
}
},
{
"apiVersion": "2016-03-30",
"dependsOn": [],
"location": "[resourceGroup().location]",
"name": "[parameters('swarmmanagerpublicIPName')]",
"properties": {
"publicIPAllocationMethod": "Dynamic",
"dnsSettings": {
"domainNameLabel": "[parameters('swarmmanagerpublicIPDnsName')]"
}
},
"tags": {
"displayName": "swarmmanagerpublicIP"
},
"type": "Microsoft.Network/publicIPAddresses"
}
],
"parameters": {
"swarmmanager1Name": { "type": "string" },
"swarmmanager1VmSize": { "type": "string" },
"adminUsername": { "type": "string" },
"adminPassword": { "type": "securestring" },
"dockerswarmstorageaccountName": { "type": "string" },
"dockerswarmstorageaccountType": { "type": "string" },
"swarmmanager1NicName": { "type": "string" },
"swarmmanagerpublicIPName": { "type": "string" },
"swarmmanager1SubnetRef": { "type": "string" },
"swarmmanager1ImagePublisher": { "type": "string" },
"swarmmanager1ImageOffer": { "type": "string" },
"windowsOSVersion": { "type": "string" },
"swarmmanager1StorageAccountContainerName": { "type": "string" },
"swarmmanager1OSDiskName": { "type": "string" },
"swarmmanagerpublicIPDnsName": { "type": "string" },
"DSCConfigurationURL": { "type": "string" },
"DSCExtensionManagerTagVersion": { "type": "string" },
"RegistrationKey": { "type": "securestring" },
"RegistrationUrl": { "type": "string" },
"LicenseType": {"type": "string"}
},
"outputs": {
"returnedIPAddress": {
"type": "string",
"value": "[reference(parameters('swarmmanager1NicName')).ipConfigurations[0].properties.privateIPAddress]"
}
}
}
if you want to pass in ps credentials do this:
"protectedSettings": {
"configurationArguments": {
"RegistrationKey": {
"userName": "whatever",
"password": "[parameters('RegistrationKey')]"
}
}
}

Deploying a logic app using ARM templates/powershell

How can I Deploy a logic app that calls a SQL DB stored procedure? I've tried the following action.
"actions": {
"Execute_stored_procedure": {
"conditions": [ ],
"inputs": {
"body": null,
"host": {
"api": {
"runtimeUrl": "https://logic-apis-northcentralus.azure-apim.net/apim/sql"
},
"connection": {
"name": "<sql connection string>"
}
},
"method": "post",
"path": "/datasets/default/procedures/#{encodeURIComponent(encodeURIComponent(string('<stored-procedure-name>')))}"
},
"type": "apiconnection"
}
}
When I deploy this template, the logic app get's created but it's throwing errors or the SQL Connection action is not showing up on the design view. What am I doing wrong here? Is Logic App for calling SQL Stored Proc supported by arm currently?
Here is a sample template for LogicApp ARM template + 'connections' resource
https://blogs.msdn.microsoft.com/logicapps/2016/02/23/deploying-in-the-logic-apps-preview-refresh/
https://github.com/jeffhollan/logicapps-deployments/blob/master/ftp_to_blob.json
I've finally figured this out from #TusharJ links and I'm posting the template I've used below to configure a LogicApp that calls a SQL DB stored procedure in specific intervals.
resources:
[
{
"type": "Microsoft.Web/connections",
"apiVersion": "2015-08-01-preview",
"location": "[resourceGroup().location]",
"name": "sqlconnector",
"properties": {
"api": {
"id": "[concat('subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/sql')]"
},
"displayName": "sqlconnector",
"parameterValues": {
"sqlConnectionString": "<sql db connection string>"
}
}
},
{
"type": "Microsoft.Logic/workflows",
"apiVersion": "2015-08-01-preview",
"name": "[parameters('logicAppName')]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "LogicApp"
},
"properties": {
"sku": {
"name": "[parameters('workflowSkuName')]",
"plan": {
"id": "[concat(resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('svcPlanName'))]"
}
},
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2015-08-01-preview/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"$connections": {
"defaultValue": { },
"type": "Object"
}
},
"triggers": {
"recurrence": {
"type": "recurrence",
"recurrence": {
"frequency": "Hour",
"interval": 1
}
}
},
"actions": {
"Execute_stored_procedure": {
"conditions": [ ],
"inputs": {
"body": null,
"host": {
"api": {
"runtimeUrl": "[concat('https://logic-apis-', resourceGroup().location, '.azure-apim.net/apim/sql')]"
},
"connection": {
"name": "#parameters('$connections')['sql']['connectionId']"
}
},
"method": "post",
"path": "/datasets/default/procedures/#{encodeURIComponent(encodeURIComponent(string('[dbo].[<Stored Proc Name>]')))}"
},
"type": "apiconnection"
}
},
"outputs": { }
},
"parameters": {
"$connections": {
"value": {
"sql": {
"connectionId": "[resourceId('Microsoft.Web/connections', 'sqlconnector')]",
"connectionName": "sqlconnector",
"id": "[reference(concat('Microsoft.Web/connections/', 'sqlconnector'), '2015-08-01-preview').api.id]"
}
}
}
}
}
}
]
Things may have changed in the API since the previous answer was given. Here is what worked for me as of 10/2016. Note: I used parameters (definitions not shown) for many of the variables:
{
"type": "Microsoft.Web/connections",
"apiVersion": "2015-08-01-preview",
"location": "[parameters('location')]",
"name": "[variables('sql_conn_name')]",
"properties": {
"api": {
"id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/sql')]"
},
"displayName": "sql_connection",
"parameterValues": {
"server": "[concat(variables('dbserver_unique_name'), '.database.windows.net')]",
"database": "[parameters('databases_name')]",
"authType": "windows",
"username": "[parameters('databases_admin_user')]",
"password": "[parameters('databases_admin_password')]"
}
}
},
{
"type": "Microsoft.Logic/workflows",
"name": "[variables('logic_app_name')]",
"apiVersion": "2016-06-01",
"location": "[parameters('location')]",
"properties": {
"state": "Enabled",
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"$connections": {
"defaultValue": { },
"type": "Object"
}
},
"triggers": {
"Recurrence": {
"recurrence": {
"frequency": "Hour",
"interval": 1
},
"type": "Recurrence"
}
},
"actions": {
"Execute_stored_procedure": {
"runAfter": { },
"type": "ApiConnection",
"inputs": {
"body": {
"timeoffset": "-4"
},
"host": {
"api": {
"runtimeUrl": "[concat('https://logic-apis-', parameters('location'), '.azure-apim.net/apim/sql')]"
},
"connection": {
"name": "#parameters('$connections')['sql']['connectionId']"
}
},
"method": "post",
"path": "/datasets/default/procedures/#{encodeURIComponent(encodeURIComponent('[dbo].[usp_UpdateHourlyOos]'))}"
}
}
},
"outputs": { }
},
"parameters": {
"$connections": {
"value": {
"sql": {
"connectionId": "[concat(subscription().id, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Web/connections/', variables('sql_conn_name'))]",
"connectionName": "[variables('sql_conn_name')]",
"id": "[concat(subscription().id,'/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/sql')]"
}
}
}
}
},
"resources": [ ],
"dependsOn": [
"[resourceId('Microsoft.Web/connections', variables('sql_conn_name'))]"
]
}

Resources