[英]Can I dynamically set the condition in an IoT Rule SQL?
in this section of yaml file, I need to update condition in sql statement.在 yaml 文件的这一部分,我需要更新 sql 语句中的条件。
for example, user can reset condition to equal 20 instead of 30.例如,用户可以将条件重置为等于 20 而不是 30。
NotifyTemperatureAlarm:
Type: 'AWS::Serverless::Function'
DependsOn: AlertSNSTopic
Properties:
CodeUri: src/notify_temperature_alarm/
Handler: app.lambda_handler
Runtime: python3.9
Architectures:
- x86_64
Events:
PutImageEvent:
Type: IoTRule
Properties:
Sql: Select * FROM 'device/temperature/alarms' where value > 30
Policies:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action: "sns:*"
Resource: "*"
Environment:
Variables:
alert_sns: !Ref AlertSNSTopic
make your condition in parameters section such as在参数部分设置您的条件,例如
Parameters:
TemperatureThreshold:
Type: Number
Default: '20'
then update NotifyTemperatureAlarm such as然后更新 NotifyTemperatureAlarm 例如
NotifyTemperatureAlarm:
Type: 'AWS::Serverless::Function'
DependsOn: AlertSNSTopic
Properties:
CodeUri: src/notify_temperature_alarm/
Handler: app.lambda_handler
Runtime: python3.9
Architectures:
- x86_64
Events:
PutImageEvent:
Type: IoTRule
Properties:
Sql: !Sub "SELECT * FROM 'device/temperature/alarms' where value > ${TemperatureThreshold}"
Policies:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action: "sns:*"
Resource: "*"
Environment:
Variables:
alert_sns: !Ref AlertSNSTopic
to make TemperatureThreshold Adjustable, you can update it from cloudformation such as要使 TemperatureThreshold 可调,您可以从 cloudformation 更新它,例如
client = boto3.client('cloudformation')
response = client.update_stack(
StackName = "your_stack_name",
UsePreviousTemplate = True,
Capabilities = ['CAPABILITY_IAM'],
Parameters=[
{
'ParameterKey': 'TemperatureThreshold',
'ParameterValue': str(new_threshold),
}
]
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.