Hi guys. I’m having trouble deploying a AWS IoT rule that contains the SQL function get. The SQL works fine if I create the rule manually through the AWS console, so my guess is that it triggers something in CloudFormation. Any idea what the problem might be? Can I “escape” the function somehow, or disable validation?
–Yaml code–
functions:
updateComponentState:
handler: updateComponentState.handler
events:
- iot:
name: “catchStateDeviceEvents”
sql: “SELECT topic(3) as stateDeviceId, timestamp as stateTime, version as stateVersion, case state.reported.activeUUID = get(state.reported.sensorUIIDs, 0).uuid when true then ‘Closed’ else ‘Open’ end as stateCurrent FROM ‘$aws/things/+/shadow/update/accepted’ WHERE regexp_matches(topic(3), ‘magnetSensor’) = true”
If I remove the get part, or put single quotes around it in the form of ‘get(state.reported.sensorUIIDs, 0).uuid’, it deploys, but obviously putting single quotes around it makes the rule defect.
–Error–
An error occurred: UpdateComponentStateIotTopicRule1 - Errors encountered while validating query.
ERROR: 1-indexed number is out of bounds: 0.
Any ideas? I’ve spent quite a bit of time trying to figure this out, but am none the wiser.
I found a solution, and as usual it turned out to be my own stupidity. Serverless deploy seems to default to sql version 2015-10-08, and it doesn’t support the get function. When I specified sql version 2016-03-23 in serverless.yml, I could deploy just fine.
If you deploy with: Type: “AWS::IoT::TopicRule”
You need to specify: AwsIotSqlVersion: “2016-03-23”
This solved my issue too.
Thanks heaps. I think the problem is with AWS’s cfn documentation. They should mention the difference between IOTSQL parser versions, and the default version is the old one before saying it’s not required.