Open GavinZZ opened 1 year ago
This issue is also reported in SAM repo, however, there is no way we can resolve this without making a backward incompatible change. The only possible workaround is to have AWS::LanguageExtensions
to support intrinsic function in DependsOn
Link to the same issue in SAM Repo https://github.com/aws/serverless-application-model/issues/2778
Thanks for raising this issue @GavinZZ. We'll triage it and will post updates here.
So, just want to confirm that I'm able to reproduce the problem. When LanguageExtensions is used then the template is passed to SAM with StageName: "local"
. When LanguageExtensions is not used then the template is passed with StageName: !Ref paramEnvironment
. And as you point out, SAM treats these two cases differently.
I want to make sure I understand your suggestion regarding the intrinsic function @GavinZZ. Are you suggesting something like this?
DependsOn: !Join
- ''
- - 'resApiGateway'
- !Ref paramEnvironment
- 'Stage'
Thanks for help investigating it. I'm suggesting exactly like you mentioned.
Just to update the status here. Thanks @GavinZZ for the suggestion. What you propose is more of a feature than a bugfix, but I also couldn't think of a simpler way to address the issue. We will discuss internally if this is a feature we want to build and if so if there is dev capacity to build it.
I am facing this same issue, in my template I am crating dynamically some Alarms that are attached to a CompositeAlarm, I want to add a dependsOn section in my CompositeAlarm to mention the logicalIds of my Alarms but since the alarms are created dynamically I am not able to use !Sub or !Join or the %d to reference them.
For the Alarm creation I am using a Count to loop throw my ressources and create an alarm for each one:
Transform:
- Count
...
Resources:
Alarm:
Count: 2
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName:
!Join
- ""
- - !Select [ 0, !Ref MyList ]
- "-my-log-alarm"
...
CompositeAlarm:
Count: 2
Type: AWS::CloudWatch::CompositeAlarm
I want to add a DependsOn section like this, but it's not working:
DependsOn:
- !Join
- ""
- - !Select [ 0, !Ref MyList ]
- "-my-log-alarm"
When I check the cloudFormation ressources, I saw that the alarms are created with logical Ids : Alarm1, Alarm2 ... So when I switch the Depends on section like bellow, it works but It's not very clean as a solution since I am giving the logical Ids list manually, for same cases I have many alarms (a) for many ressources (r) then I have to add a x r lines
DependsOn:
- Alarm1
- Alarm2
is there any clean solution for this please?
@MalikAtalla-AWS Any update on this feature? I've a number of reports that customers are stuck due to this conflict.
Community Note
Tell us about the bug
It appears that if
AWS::LanguageExtensions
is removed,paramEnvironment
is treated as an intrinsic function, then theAWS::ApiGateway::Stage
resource gets correct generated with the nameresApiGatewayStage
. However, if we addAWS::LanguageExtensions
,paramEnvironment
is a fixed value afterAWS::LanguageExtensions
transform, then the resource name for ApiGateway Stage becomesresApiGatewaylocalStage
. Code for the above logic can be found hereHowever, if there is another resource say
resUsagePlan
that depends on the generated resourceAWS::ApiGateway::Stage
, this would be a deadlock for the customer because they don't know the exact generated name (depending onparamEnvironment
), andAWS::LanguageExtensions
doesn't allow intrinsics function inDependsOn
.Additional context
I do NOT think it's a bug from either SAM Transform or
AWS::LanguageExtensions
transform itself. However, when they both exists in a template like described above, customers can only resolve this issue by using intrinsic function inDependsOn
, which is not supported byLanguageExtensions