事象 : CloudFormationでEventBridgeのRuleを登録したらエラー
テンプレートファイルにEventBridgeのルールを追加して・・・
# ...省略...
EventBridgeRuleCase1:
Type: AWS::Events::Rule
Properties:
Name: !Sub ${AWS::StackName}-event-bridge-rule-long-long-long-long-name
ScheduleExpression: 'cron(0 12 * * ? *)'
Targets:
- Arn: !GetAtt Cluster.Arn
RoleArn: !Sub arn:aws:iam::${AWS::AccountId}:role/ecsEventsRole
Id: !Sub ${AWS::StackName}-event-bridge-rule-long-long-long-long-name
# ...省略...
CloudFormationのスタックをテンプレートファイルで更新・・・しらたエラーになりました。
1 validation error detected: Value 'ecs-cluster-very-long-long-name-event-bridge-rule-long-long-long-long-name' at 'name' failed to satisfy constraint: Member must have length less than or equal to 64 (Service: AmazonCloudWatchEvents; Status Code: 400; Error Code: ValidationException; Request ID: 6xxxxx-xxxx-xxx-xxxxxx; Proxy: null)
原因 : ルールのNameは文字数上限が64文字までだから
擬似パラメーターAWS::StackName
にはECSのクラスター名が入ります。
結果、ルール名は70文字近くになっていました。
Name
The name of the rule.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 64.
Pattern: [.-_A-Za-z0-9]+
Required: No
Rule - Amazon EventBridge
TargetのIdも同じく64文字まででした。
Id
The ID of the target within the specified rule. Use this ID to reference the target when updating the rule. We recommend using a memorable and unique string.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 64.
Pattern: [.-_A-Za-z0-9]+
Required: Yes
Target - Amazon EventBridge
対応 : NameとIdを短くする
# ...省略...
Properties:
Name: !Sub ${AWS::StackName}-event-bridge-rule-name
# ...省略...
Id: !Sub ${AWS::StackName}-event-bridge-rule-name
# ...省略...
- テンプレートファイルを短い文字列へ修正
- CloudFormationで今一度アップロードして登録
- 成功
- 戒め : 文字数制限はちゃんと確認する、特に擬似パラメーターを使うときは。