AWS Step Functions - Arrays - amazon-web-services

Given the following, I would like to know how I can access the 'exists' field. I thought it was simply $.result.exists or $.result[0].exists but neither of these work? Also is there a way I can extract all occurrences of 'exists' from the array and use them in a choice flow using Step Functions?
[
{
"result": {
"exists": true
},
"StatusCode": 200
},
{
"result": {
"exists": true
},
"StatusCode": 200
}
]
Even better I would like to transform the following input:
"output": [
[
{
"result": {
"exists": true
},
"StatusCode": 200
},
{
"result": {
"exists": true
},
"StatusCode": 200
}
],
{
"result": {
"exists": true
},
"StatusCode": 200
}
]
into the following one array:
[
{
"result": {
"exists": true
},
"StatusCode": 200
},
{
"result": {
"exists": true
},
"StatusCode": 200
}
{
"result": {
"exists": true
},
"StatusCode": 200
}
]
Is this possible? Any suggestions welcome!

Related

Resource handler returned message: "Invalid request (Service: Connect, Status Code: 400)

I am trying to create Amazon Connect Contact flows using the cloudformation template and Amazon Contact flow language which is new for me. But I am
facing this issue and the stack fails to create. I am not sure If I am having syntax errors in my yml file.
Complete error message
Resource handler returned message: "Invalid request (Service: Connect, Status Code: 400, Request ID: aa1e1049-47bb-43ea-8065-0f8b1cf503d2)" (RequestToken: ff62940b-0e60-2308-d33d-917eeb399402, HandlerErrorCode: InvalidRequest)
Here is the cloud formation template
---
AWSTemplateFormatVersion: "2010-09-09"
Description: "Amazon Connect - Contact Flow"
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "General Information"
Parameters:
- SystemName
- EnvironmentName
- Label:
default: "Amazon Connect Information"
Parameters:
- InstanceID
- ContactFlowName
Parameters:
SystemName:
Type: String
EnvironmentName:
Type: String
AllowedValues: [prd, stg, dev]
InstanceID:
Type: String
Description: "Enter the Amazon Connect Instance ID (e.g. 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx')"
ContactFlowName:
Type: String
Description: "Enter the Name of the Contact flow"
Resources:
ContactFlow:
Type: 'AWS::Connect::ContactFlow'
Properties:
Name: !Sub "${ContactFlowName}"
Description: Example contact flow
InstanceArn: !Sub "arn:aws:connect:${AWS::Region}:${AWS::AccountId}:instance/${InstanceID}"
Type: CONTACT_FLOW
Content: |
{
"Version": "2019-10-30",
"StartAction": "c8275c19-08aa-4ee5-9b42-bcc47d32e914",
"Metadata": {
"entryPointPosition": {
"x": 20,
"y": 20
},
"snapToGrid": false,
"ActionMetadata": {
"5c47b68e-d790-45eb-a0bd-654027af4868": {
"position": {
"x": 463,
"y": 491
},
"useDynamic": false
},
"c8275c19-08aa-4ee5-9b42-bcc47d32e914": {
"position": {
"x": 180,
"y": 20
},
"conditionMetadata": [
{
"id": "6a7b09ef-d441-4183-8ef3-2f0f360ba747",
"value": "1"
},
{
"id": "f3516737-c758-4d6f-8d31-ea43d1e27990",
"value": "2"
},
{
"id": "21ad3977-2559-4449-ba54-b84d4a0521b6",
"value": "3"
}
],
"useDynamic": false,
"useLexBotDropdown": true,
"useDynamicLexBotArn": false
},
"c36d9f86-780d-4c44-8c79-80c8353a699a": {
"position": {
"x": 1068,
"y": 317
}
},
"14837518-cc08-4d54-ac93-ea7e063481a8": {
"position": {
"x": 492,
"y": 340
},
"overrideConsoleVoice": false,
"defaultVoice": "Standard"
},
"1e435e5f-7b62-4938-8c9f-fa05106c72b3": {
"position": {
"x": 501,
"y": 174
},
"overrideConsoleVoice": false,
"defaultVoice": "Standard"
},
"98768cdb-f5e6-4642-90e3-6e06fd6813e8": {
"position": {
"x": 478,
"y": 21
},
"overrideConsoleVoice": false,
"defaultVoice": "Conversational",
"fragments": {
"SetContactData": "bc981918-e0b3-4840-afa5-12b6d7078248"
}
},
"bc981918-e0b3-4840-afa5-12b6d7078248": {
"position": {
"x": 0,
"y": 0
}
},
"3a521089-edfe-4821-8156-19014b7b8926": {
"position": {
"x": 716,
"y": 45
},
"useDynamic": false,
"ContactFlow": {
"id": "arn:aws:connect:eu-central-1:132387760551:instance/a65f970f-0f59-444e-b421-5ec6ec74c116/contact-flow/d727e34f-6707-437f-8013-20e4f2a867d6",
"text": "Transaction Banking Authentication"
}
}
}
},
"Actions": [
{
"Identifier": "5c47b68e-d790-45eb-a0bd-654027af4868",
"Parameters": {
"Text": "An Error Occured!"
},
"Transitions": {
"NextAction": "c36d9f86-780d-4c44-8c79-80c8353a699a",
"Errors": [
{
"NextAction": "c36d9f86-780d-4c44-8c79-80c8353a699a",
"ErrorType": "NoMatchingError"
}
],
"Conditions": []
},
"Type": "MessageParticipant"
},
{
"Identifier": "c8275c19-08aa-4ee5-9b42-bcc47d32e914",
"Parameters": {
"Text": "To continue in English press 1, Ukuqhubeka ngesiZulu cindezela u- 2, Vir Afrikaans Druk 3.",
"StoreInput": "False",
"InputTimeLimitSeconds": "5"
},
"Transitions": {
"NextAction": "5c47b68e-d790-45eb-a0bd-654027af4868",
"Errors": [
{
"NextAction": "5c47b68e-d790-45eb-a0bd-654027af4868",
"ErrorType": "NoMatchingError"
},
{
"NextAction": "5c47b68e-d790-45eb-a0bd-654027af4868",
"ErrorType": "NoMatchingCondition"
},
{
"NextAction": "5c47b68e-d790-45eb-a0bd-654027af4868",
"ErrorType": "InputTimeLimitExceeded"
}
],
"Conditions": [
{
"NextAction": "98768cdb-f5e6-4642-90e3-6e06fd6813e8",
"Condition": {
"Operator": "Equals",
"Operands": [
"1"
]
}
},
{
"NextAction": "1e435e5f-7b62-4938-8c9f-fa05106c72b3",
"Condition": {
"Operator": "Equals",
"Operands": [
"2"
]
}
},
{
"NextAction": "14837518-cc08-4d54-ac93-ea7e063481a8",
"Condition": {
"Operator": "Equals",
"Operands": [
"3"
]
}
}
]
},
"Type": "GetParticipantInput"
},
{
"Identifier": "c36d9f86-780d-4c44-8c79-80c8353a699a",
"Type": "DisconnectParticipant",
"Parameters": {},
"Transitions": {}
},
{
"Identifier": "14837518-cc08-4d54-ac93-ea7e063481a8",
"Parameters": {
"TextToSpeechVoice": "Lotte"
},
"Transitions": {
"NextAction": "3a521089-edfe-4821-8156-19014b7b8926",
"Errors": [],
"Conditions": []
},
"Type": "UpdateContactTextToSpeechVoice"
},
{
"Identifier": "1e435e5f-7b62-4938-8c9f-fa05106c72b3",
"Parameters": {
"TextToSpeechVoice": "Marlene"
},
"Transitions": {
"NextAction": "3a521089-edfe-4821-8156-19014b7b8926",
"Errors": [],
"Conditions": []
},
"Type": "UpdateContactTextToSpeechVoice"
},
{
"Identifier": "98768cdb-f5e6-4642-90e3-6e06fd6813e8",
"Parameters": {
"TextToSpeechVoice": "Joanna"
},
"Transitions": {
"NextAction": "bc981918-e0b3-4840-afa5-12b6d7078248",
"Errors": [],
"Conditions": []
},
"Type": "UpdateContactTextToSpeechVoice"
},
{
"Identifier": "bc981918-e0b3-4840-afa5-12b6d7078248",
"Parameters": {
"LanguageCode": "en-US"
},
"Transitions": {
"NextAction": "3a521089-edfe-4821-8156-19014b7b8926",
"Errors": [
{
"NextAction": "3a521089-edfe-4821-8156-19014b7b8926",
"ErrorType": "NoMatchingError"
}
],
"Conditions": []
},
"Type": "UpdateContactData"
},
{
"Identifier": "3a521089-edfe-4821-8156-19014b7b8926",
"Parameters": {
"ContactFlowId": "arn:aws:connect:eu-central-1:132387760551:instance/a65f970f-0f59-444e-b421-5ec6ec74c116/contact-flow/d727e34f-6707-437f-8013-20e4f2a867d6"
},
"Transitions": {
"NextAction": "c36d9f86-780d-4c44-8c79-80c8353a699a",
"Errors": [
{
"NextAction": "c36d9f86-780d-4c44-8c79-80c8353a699a",
"ErrorType": "NoMatchingError"
}
],
"Conditions": []
},
"Type": "TransferToFlow"
}
]
Tags:
- Key: System
Value: !Ref SystemName
- Key: Environment
Value: !Ref EnvironmentName
Any kinda help will Appreciated
Okay, looks like the Content object is not valid. For starters it ends with a ] character instead of a } But even fixing that it has issues.
I'd suggest creating a flow in the gui and export it, then use the json from that as a template.
Also, check the Flow language documentation to get the syntax and structure correct.

How to I get just the temperature from the new google SDM for nest thermostat

Using : Get
https://smartdevicemanagement.googleapis.com/v1/enterprises/project-id/devices/device-id/
It returns all the info below. i just want the temperature. I am using postnam with: Content-Type and Authorization.
{
"name": "enterprises/c7ad210f-e05d-418c-a52a-1efc0891b3cf/devices/AVPHwEu-AUnrc2QEy_wmf7_u1hXWh_fH2V4q_DA5S1C3_bnLc2H-IxPEsNKtbc5NJZGCXFNAgK9HyZ96slFUQuyShlqauw",
"type": "sdm.devices.types.THERMOSTAT",
"assignee": "enterprises/c7ad210f-e05d-418c-a52a-1efc0891b3cf/structures/AVPHwEsL0trQSBq4GoBJFNrt_eBujz2A9uQvOxg112ZkvUSGMw3A2l3BBFGrLQ-Q8nyc-Mvvqb-Dy6YabT4625fGH1fcIg/rooms/AVPHwEuauRh8KXX1R_kRoTnxKUXRomQ_u80JOyjhfVKKCbn-OPPPigjoAOIJ7kFFwy1-PEs9z6BIP4DugImZLQ2bL59Uv0nZuHLjVsb0If9q0-pGQZcFgY5dxx7iIX63GuIezOW4paE8NNE",
"traits": {
"sdm.devices.traits.Info": {
"customName": ""
},
"sdm.devices.traits.Humidity": {
"ambientHumidityPercent": 63
},
"sdm.devices.traits.Connectivity": {
"status": "ONLINE"
},
"sdm.devices.traits.Fan": {},
"sdm.devices.traits.ThermostatMode": {
"mode": "HEAT",
"availableModes": [
"HEAT",
"OFF"
]
},
"sdm.devices.traits.ThermostatEco": {
"availableModes": [
"OFF",
"MANUAL_ECO"
],
"mode": "OFF",
"heatCelsius": 8.82,
"coolCelsius": 24.44443
},
"sdm.devices.traits.ThermostatHvac": {
"status": "OFF"
},
"sdm.devices.traits.Settings": {
"temperatureScale": "CELSIUS"
},
"sdm.devices.traits.ThermostatTemperatureSetpoint": {
"heatCelsius": 16
},
"sdm.devices.traits.Temperature": {
"ambientTemperatureCelsius": 20.23
}
},
"parentRelations": [
{
"parent": "enterprises/c7ad210f-e05d-418c-a52a-1efc0891b3cf/structures/AVPHwEsL0trQSBq4GoBJFNrt_eBujz2A9uQvOxg112ZkvUSGMw3A2l3BBFGrLQ-Q8nyc-Mvvqb-Dy6YabT4625fGH1fcIg/rooms/AVPHwEuauRh8KXX1R_kRoTnxKUXRomQ_u80JOyjhfVKKCbn-OPPPigjoAOIJ7kFFwy1-PEs9z6BIP4DugImZLQ2bL59Uv0nZuHLjVsb0If9q0-pGQZcFgY5dxx7iIX63GuIezOW4paE8NNE",
"displayName": "Hallway"
}
]
}
According to the API documentation, it's not possible to only get the temperature.
But you can get it from the response body you posted, in Postman's test tab:
const resBody = pm.response.json();
temperature = resBody.traits['sdm.devices.traits.Temperature'].ambientTemperatureCelsius;
console.log(temperature);

How can I exclude results from elasticsearch based on the contents of a field?

I'm using elasticsearch on AWS to store logs from Cloudfront. I have created a simple query that will give me all entries from the past 24h, sorted from new to old:
{
"from": 0,
"size": 1000,
"query": {
"bool": {
"must": [
{ "match": { "site_name": "some-site" } }
],
"filter": [
{
"range": {
"timestamp": {
"lt": "now",
"gte": "now-1d"
}
}
}
]
}
},
"sort": [
{ "timestamp": { "order": "desc" } }
]
}
Now, there a are certain sources (based on the user agent) for which I would like to exclude results. So my question boils down to this:
How can I filter out entries from the results when a certain field contains a certain string? Or:
query.filter.where('cs_user_agent').does.not.contain('Some string')
(This is not real code, obviously.)
I have tried to make sense of the Elasticsearch documentation, but I couldn't find a good example of how to achieve this.
I hope this makes sense. Thanks in advance!
Okay, I figured it out. What I've done is use a Bool Query in combination with a wildcard:
{
"from": 0,
"size": 1000,
"query": {
"bool": {
"must": [
{ "match": { "site_name": "some-site" } }
],
"filter": [
{
"range": {
"timestamp": {
"lt": "now",
"gte": "now-1d"
}
}
}
],
"must_not": [
{ "wildcard": { "cs_user_agent": "some string*" } }
]
}
},
"sort": [
{ "timestamp": { "order": "desc" } }
]
}
This basically matches any user agent string containing "some string", and then filters it out (because of the "must_not").
I hope this helps others who run into this problem.
nod.js client version:
const { from, size, value, tagsIdExclude } = req.body;
const { body } = await elasticWrapper.client.search({
index: ElasticIndexs.Tags,
body: {
from: from,
size: size,
query: {
bool: {
must: {
wildcard: {
name: {
value: `*${value}*`,
boost: 1.0,
rewrite: 'constant_score',
},
},
},
filter: {
bool: {
must_not: [
{
terms: {
id: tagsIdExclude ? tagsIdExclude : [],
},
},
],
},
},
},
},
},
});

AWS cloudfront cli not creating web distribution for custom origin with compress parameter

I was looking to create AWS cloudfront web distribution using CLI, everything was working fine until I tried to add "Compress": True to the distribution's JSON.
Following is my configuration
{
"CallerReference": "string",
"Aliases": {
"Items": [
"test.example.com"
],
"Quantity": 1
},
"DefaultRootObject": "",
"Origins": {
"Items": [
{
"OriginPath": "",
"CustomOriginConfig": {
"OriginProtocolPolicy": "match-viewer",
"HTTPPort": 80,
"HTTPSPort": 443
},
"Id": "Custom-example.com",
"DomainName": "example.com"
}
],
"Quantity": 1
},
"DefaultCacheBehavior": {
"TrustedSigners": {
"Enabled": false,
"Quantity": 0
},
"TargetOriginId": "Custom-example.com",
"ViewerProtocolPolicy": "allow-all",
"ForwardedValues": {
"Headers": {
"Quantity": 0
},
"Cookies": {
"Forward": "none"
},
"QueryString": false
},
"MaxTTL": 31536000,
"Compress": true,
"SmoothStreaming": false,
"DefaultTTL": 86400,
"AllowedMethods": {
"Items": [
"HEAD",
"GET"
],
"CachedMethods": {
"Items": [
"HEAD",
"GET"
],
"Quantity": 2
},
"Quantity": 2
},
"MinTTL": 0
},
"CacheBehaviors": {
"Quantity": 2,
"Items": [ {
"TrustedSigners": {
"Enabled": false,
"Quantity": 0
},
"TargetOriginId": "Custom-example.com",
"ViewerProtocolPolicy": "allow-all",
"ForwardedValues": {
"Headers": {
"Quantity": 0
},
"Cookies": {
"Forward": "none"
},
"QueryString": false
},
"MaxTTL": 31536000,
"Compress": true,
"PathPattern": "*.jpeg",
"SmoothStreaming": false,
"DefaultTTL": 86400,
"AllowedMethods": {
"Items": [
"HEAD",
"GET"
],
"CachedMethods": {
"Items": [
"HEAD",
"GET"
],
"Quantity": 2
},
"Quantity": 2
},
"MinTTL": 60
}
,
{
"TrustedSigners": {
"Enabled": false,
"Quantity": 0
},
"TargetOriginId": "Custom-example.com",
"ViewerProtocolPolicy": "allow-all",
"ForwardedValues": {
"Headers": {
"Quantity": 0
},
"Cookies": {
"Forward": "none"
},
"QueryString": false
},
"MaxTTL": 31536000,
"Compress": true,
"PathPattern": "*.png",
"SmoothStreaming": false,
"DefaultTTL": 86400,
"AllowedMethods": {
"Items": [
"HEAD",
"GET"
],
"CachedMethods": {
"Items": [
"HEAD",
"GET"
],
"Quantity": 2
},
"Quantity": 2
},
"MinTTL": 100
}
]
},
"CustomErrorResponses": {
"Quantity": 0
},
"Comment": "my distro",
"Logging": {
"Bucket": "",
"Prefix": "",
"Enabled": false,
"IncludeCookies": false
},
"PriceClass": "PriceClass_100",
"Enabled": true,
"ViewerCertificate": {
"CloudFrontDefaultCertificate": true,
"MinimumProtocolVersion": "SSLv3"
},
"Restrictions": {
"GeoRestriction": {
"Items": [
"IN",
"GB",
"IR"
],
"RestrictionType": "whitelist",
"Quantity": 3
}
},
"WebACLId": ""
}
This is the error I get
If I remove the compress parameter It works fine.
Parameter validation failed:
Unknown parameter in DistributionConfig.DefaultCacheBehavior: "Compress", must be one of: TargetOriginId, ForwardedValues, TrustedSigners, ViewerProtocolPolicy, MinTTL, AllowedMethods, SmoothStreaming, DefaultTTL, MaxTTL
Unknown parameter in DistributionConfig.CacheBehaviors.Items[0]: "Compress", must be one of: PathPattern, TargetOriginId, ForwardedValues, TrustedSigners, ViewerProtocolPolicy, MinTTL, AllowedMethods, SmoothStreaming, DefaultTTL, MaxTTL
Unknown parameter in DistributionConfig.CacheBehaviors.Items[1]: "Compress", must be one of: PathPattern, TargetOriginId, ForwardedValues, TrustedSigners, ViewerProtocolPolicy, MinTTL, AllowedMethods, SmoothStreaming, DefaultTTL, MaxTTL
After raising a ticket with AWS I got to know that my cloudfront distribution JSON is absolutely fine, the thing which was giving the headache was the CLI version
I was using AWS CLI version 1.9.12 while compress supports only with CLI version >= 1.9.14

AWS CLI create cloudfront distribution: --distribution-config

Trying a cloudfront distribution using the AWS CLI, one needs an argument --distribution-config
aws cloudfront create-distribution
aws: error: argument --distribution-config is required
I assume this is a json string with the configuration for the distribution, but I cannot find any documentation about it.
Where can I find a minimal working example?
The following JSON worked for me. I used get-distribution-config to generate it.
{
"Comment": "example json",
"CacheBehaviors": {
"Quantity": 0
},
"Logging": {
"Bucket": null,
"Prefix": null,
"Enabled": false,
"IncludeCookies": false
},
"Origins": {
"Items": [
{
"S3OriginConfig": {
"OriginAccessIdentity": null
},
"Id": "S3-origin",
"DomainName": "example.s3.amazonaws.com"
}
],
"Quantity": 1
},
"DefaultRootObject": null,
"PriceClass": "PriceClass_All",
"Enabled": false,
"DefaultCacheBehavior": {
"TrustedSigners": {
"Enabled": false,
"Quantity": 0
},
"TargetOriginId": "S3-origin",
"ViewerProtocolPolicy": "allow-all",
"ForwardedValues": {
"Headers": {
"Quantity": 0
},
"Cookies": {
"Forward": "none"
},
"QueryString": false
},
"SmoothStreaming": false,
"AllowedMethods": {
"Items": [
"GET",
"HEAD"
],
"Quantity": 2
},
"MinTTL": 0
},
"CallerReference": "example",
"ViewerCertificate": {
"CloudFrontDefaultCertificate": true
},
"CustomErrorResponses": {
"Quantity": 0
},
"Restrictions": {
"GeoRestriction": {
"RestrictionType": "none",
"Quantity": 0
}
},
"Aliases": {
"Quantity": 0
}
}
As stated in the documentation you could try to run this command:
aws cloudfront create-distribution --distribution-config file://distconfig.json
The file distconfig.json is a JSON document in the current folder that defines a CloudFront distribution:
distconfig.json
{
"CallerReference": "my-distribution-2015-09-01",
"Aliases": {
"Quantity": 0
},
"DefaultRootObject": "index.html",
"Origins": {
"Quantity": 1,
"Items": [
{
"Id": "my-origin",
"DomainName": "my-bucket.s3.amazonaws.com",
"S3OriginConfig": {
"OriginAccessIdentity": ""
}
}
]
},
"DefaultCacheBehavior": {
"TargetOriginId": "my-origin",
"ForwardedValues": {
"QueryString": true,
"Cookies": {
"Forward": "none"
}
},
"TrustedSigners": {
"Enabled": false,
"Quantity": 0
},
"ViewerProtocolPolicy": "allow-all",
"MinTTL": 3600
},
"CacheBehaviors": {
"Quantity": 0
},
"Comment": "",
"Logging": {
"Enabled": false,
"IncludeCookies": true,
"Bucket": "",
"Prefix": ""
},
"PriceClass": "PriceClass_All",
"Enabled": true
}
If you follow the link I provided, you will have more information about the output this command will give you.