本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
比對 Amazon EventBridge 中 null 值和空字串的事件
重要
您可以建立符合具有 Null 值或空字串的事件中欄位的事件模式。請考量下列範例事件。
查看最佳做法,以避免高於預期的費用和限流
{
"version": "0",
"id": "3e3c153a-8339-4e30-8c35-687ebef853fe",
"detail-type": "EC2 Instance Launch Successful",
"source": "aws.autoscaling",
"account": "123456789012",
"time": "2015-11-11T21:31:47Z",
"region": "us-east-1",
"resources": [
],
"detail": {
"eventVersion": "",
"responseElements": null
}
}
若要符合 eventVersion 的值為空字串的事件,請使用下列符合先前事件的事件模式。
{
"detail": {
"eventVersion": [""]
}
}若要符合 responseElements 的值為 Null 的事件,請使用下列符合先前事件的事件模式。
{
"detail": {
"responseElements": [null]
}
}注意
在模式比對中,Null 值和空字串不是可交換的。符合空字符串的事件模式與 null 的值不匹配。
在 AWS CloudFormation 範本中使用 null 值
AWS CloudFormation 不允許 範本中的null值。如果您使用 YAML 或 JSON 物件語法定義具有 null 值的事件模式,範本驗證會失敗並顯示錯誤:'null' values are not allowed in templates。
若要解決此限制,請將 EventPattern 屬性指定為 JSON 字串,而非 YAML 或 JSON 物件。下列範例示範如何比對 AWS CloudFormation 範本中的 null 值:
MyRule:
Type: AWS::Events::Rule
Properties:
EventPattern: '{"detail":{"responseElements":[null]}}'