Skip to content

Commit b9d4f81

Browse files
authored
fix: Remove logical id change for Events Rule (#2972)
1 parent aa657e9 commit b9d4f81

File tree

4 files changed

+61
-79
lines changed

4 files changed

+61
-79
lines changed

samtranslator/model/events.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
from typing import Any, Dict, List, Optional
2-
31
from samtranslator.model import GeneratedProperty, Resource
42
from samtranslator.model.intrinsics import fnGetAtt, ref
53

64
# Event Rule Targets Id and Logical Id has maximum 64 characters limit
75
# https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_Target.html
8-
EVENT_RULE_LOGICAL_ID_MAX_LENGTH = 64
9-
EVENT_RULE_LOGICAL_ID_EVENT_SUFFIX = "Event"
6+
_EVENT_RULE_TARGET_ID_MAX_LENGTH = 64
107

118

129
class EventsRule(Resource):
@@ -24,28 +21,13 @@ class EventsRule(Resource):
2421

2522
runtime_attrs = {"rule_id": lambda self: ref(self.logical_id), "arn": lambda self: fnGetAtt(self.logical_id, "Arn")}
2623

27-
def __init__(
28-
self,
29-
logical_id: Optional[Any],
30-
relative_id: Optional[str] = None,
31-
depends_on: Optional[List[str]] = None,
32-
attributes: Optional[Dict[str, Any]] = None,
33-
) -> None:
34-
super().__init__(logical_id, relative_id, depends_on, attributes)
35-
36-
if len(self.logical_id) > EVENT_RULE_LOGICAL_ID_MAX_LENGTH:
37-
# Truncate logical id to satisfy the EVENT_RULE_ID_MAX_LENGTH limit
38-
self.logical_id = _truncate_with_suffix(
39-
self.logical_id, EVENT_RULE_LOGICAL_ID_MAX_LENGTH, EVENT_RULE_LOGICAL_ID_EVENT_SUFFIX
40-
)
41-
4224

4325
def generate_valid_target_id(logical_id: str, suffix: str) -> str:
44-
"""Truncate Target Id if it is exceeding EVENT_RULE_ID_MAX_LENGTH limi."""
45-
if len(logical_id) + len(suffix) <= EVENT_RULE_LOGICAL_ID_MAX_LENGTH:
26+
"""Truncate Target Id if it is exceeding _EVENT_RULE_TARGET_ID_MAX_LENGTH limit."""
27+
if len(logical_id) + len(suffix) <= _EVENT_RULE_TARGET_ID_MAX_LENGTH:
4628
return logical_id + suffix
4729

48-
return _truncate_with_suffix(logical_id, EVENT_RULE_LOGICAL_ID_MAX_LENGTH, suffix)
30+
return _truncate_with_suffix(logical_id, _EVENT_RULE_TARGET_ID_MAX_LENGTH, suffix)
4931

5032

5133
def _truncate_with_suffix(s: str, length: int, suffix: str) -> str:

tests/translator/output/aws-cn/event_bridge_rule_super_long_id.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
{
22
"Resources": {
3-
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWiEvent": {
4-
"Properties": {
5-
"ScheduleExpression": "cron(05 12 * * ? *)",
6-
"Targets": [
7-
{
8-
"Arn": {
9-
"Fn::GetAtt": [
10-
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserException",
11-
"Arn"
12-
]
13-
},
14-
"Id": "QueryForAvailabilityWithUserExceptionQueryForAvailabLambdaTarget"
15-
}
16-
]
17-
},
18-
"Type": "AWS::Events::Rule"
19-
},
203
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserException": {
214
"Properties": {
225
"Code": {
@@ -39,6 +22,23 @@
3922
},
4023
"Type": "AWS::Lambda::Function"
4124
},
25+
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionEvent": {
26+
"Properties": {
27+
"ScheduleExpression": "cron(05 12 * * ? *)",
28+
"Targets": [
29+
{
30+
"Arn": {
31+
"Fn::GetAtt": [
32+
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserException",
33+
"Arn"
34+
]
35+
},
36+
"Id": "QueryForAvailabilityWithUserExceptionQueryForAvailabLambdaTarget"
37+
}
38+
]
39+
},
40+
"Type": "AWS::Events::Rule"
41+
},
4242
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionEventPermission": {
4343
"Properties": {
4444
"Action": "lambda:InvokeFunction",
@@ -48,7 +48,7 @@
4848
"Principal": "events.amazonaws.com",
4949
"SourceArn": {
5050
"Fn::GetAtt": [
51-
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWiEvent",
51+
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionEvent",
5252
"Arn"
5353
]
5454
}
@@ -226,7 +226,7 @@
226226
},
227227
"Type": "AWS::IAM::Role"
228228
},
229-
"SuperSuperSuperSuperLongNameForStepFunctionSuperSuperSuperSEvent": {
229+
"SuperSuperSuperSuperLongNameForStepFunctionSuperSuperSuperSuperLongNameForStepFunctionCWEventEvent": {
230230
"Properties": {
231231
"EventPattern": {
232232
"detail": {

tests/translator/output/aws-us-gov/event_bridge_rule_super_long_id.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
{
22
"Resources": {
3-
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWiEvent": {
4-
"Properties": {
5-
"ScheduleExpression": "cron(05 12 * * ? *)",
6-
"Targets": [
7-
{
8-
"Arn": {
9-
"Fn::GetAtt": [
10-
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserException",
11-
"Arn"
12-
]
13-
},
14-
"Id": "QueryForAvailabilityWithUserExceptionQueryForAvailabLambdaTarget"
15-
}
16-
]
17-
},
18-
"Type": "AWS::Events::Rule"
19-
},
203
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserException": {
214
"Properties": {
225
"Code": {
@@ -39,6 +22,23 @@
3922
},
4023
"Type": "AWS::Lambda::Function"
4124
},
25+
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionEvent": {
26+
"Properties": {
27+
"ScheduleExpression": "cron(05 12 * * ? *)",
28+
"Targets": [
29+
{
30+
"Arn": {
31+
"Fn::GetAtt": [
32+
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserException",
33+
"Arn"
34+
]
35+
},
36+
"Id": "QueryForAvailabilityWithUserExceptionQueryForAvailabLambdaTarget"
37+
}
38+
]
39+
},
40+
"Type": "AWS::Events::Rule"
41+
},
4242
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionEventPermission": {
4343
"Properties": {
4444
"Action": "lambda:InvokeFunction",
@@ -48,7 +48,7 @@
4848
"Principal": "events.amazonaws.com",
4949
"SourceArn": {
5050
"Fn::GetAtt": [
51-
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWiEvent",
51+
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionEvent",
5252
"Arn"
5353
]
5454
}
@@ -226,7 +226,7 @@
226226
},
227227
"Type": "AWS::IAM::Role"
228228
},
229-
"SuperSuperSuperSuperLongNameForStepFunctionSuperSuperSuperSEvent": {
229+
"SuperSuperSuperSuperLongNameForStepFunctionSuperSuperSuperSuperLongNameForStepFunctionCWEventEvent": {
230230
"Properties": {
231231
"EventPattern": {
232232
"detail": {

tests/translator/output/event_bridge_rule_super_long_id.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
{
22
"Resources": {
3-
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWiEvent": {
4-
"Properties": {
5-
"ScheduleExpression": "cron(05 12 * * ? *)",
6-
"Targets": [
7-
{
8-
"Arn": {
9-
"Fn::GetAtt": [
10-
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserException",
11-
"Arn"
12-
]
13-
},
14-
"Id": "QueryForAvailabilityWithUserExceptionQueryForAvailabLambdaTarget"
15-
}
16-
]
17-
},
18-
"Type": "AWS::Events::Rule"
19-
},
203
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserException": {
214
"Properties": {
225
"Code": {
@@ -39,6 +22,23 @@
3922
},
4023
"Type": "AWS::Lambda::Function"
4124
},
25+
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionEvent": {
26+
"Properties": {
27+
"ScheduleExpression": "cron(05 12 * * ? *)",
28+
"Targets": [
29+
{
30+
"Arn": {
31+
"Fn::GetAtt": [
32+
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserException",
33+
"Arn"
34+
]
35+
},
36+
"Id": "QueryForAvailabilityWithUserExceptionQueryForAvailabLambdaTarget"
37+
}
38+
]
39+
},
40+
"Type": "AWS::Events::Rule"
41+
},
4242
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionEventPermission": {
4343
"Properties": {
4444
"Action": "lambda:InvokeFunction",
@@ -48,7 +48,7 @@
4848
"Principal": "events.amazonaws.com",
4949
"SourceArn": {
5050
"Fn::GetAtt": [
51-
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWiEvent",
51+
"QueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionQueryForAvailabilityWithUserExceptionEvent",
5252
"Arn"
5353
]
5454
}
@@ -218,7 +218,7 @@
218218
},
219219
"Type": "AWS::IAM::Role"
220220
},
221-
"SuperSuperSuperSuperLongNameForStepFunctionSuperSuperSuperSEvent": {
221+
"SuperSuperSuperSuperLongNameForStepFunctionSuperSuperSuperSuperLongNameForStepFunctionCWEventEvent": {
222222
"Properties": {
223223
"EventPattern": {
224224
"detail": {

0 commit comments

Comments
 (0)