You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support CloudFormation intrinsic functions in SAM resources #22
We quite often use !Ref, !Sub, !Join in properties that are supposed to hold strings such as CodeUri, DefinitionUri, StageName (#19) etc. This is a perfectly valid CloudFormation, but the transformation logic that parses SAM does not resolve intrinsic functions before parsing the property as a string. So the transformation logic would fail and depending on the property it could either return a validation error or internal failure. Properties that are directly passed down to CloudFormation are unaffected by this problem.
This is a feature request to add support for resolving a subset of CloudFormation intrinsics in the transformation logic. We care about only the subset of properties that the transform manipulates, like CodeUri.
Following intrinsics will be supported:
!Sub
!Join
on following properties:
CodeUri on AWS::Serverless::Function
Role on AWS::Serverless::Function
DefinitionUri on AWS::Serverless::Api
StageName on AWS::Serverless::Api
Reacted by David Sciamma, natgaertner, Alexander Schachtschabel, Stefan Borsje, Jaco le Roux, Daichi Ueura, Michael Wittig, Jeremy Olexa, Denis Loginov, Koji Nakayama and 7 more
@sanathkr Thank you for your response. Is there a reason why ARNs in particular cannot be passed as I had made the assumption that the stage variable was just a string i was setting? I would not have assumed that the contents of the string would be validated.
I'm experiencing a variation of this trying to use !Ref as a value in a Function's Environment. Is my only option to switch to AWS::Lambda::Function for now?
Edit: I had a typo in my CodeUri attribute and that caused "internal error in transform" which led me here. Sorry.
Our org would also like to see !Ref supported in a the CodeUri field of a AWS::Serverless::Function in addition to the proposed items in the original comment.
Something like this, is what we are thinking (idolized design):
Sorry, removed my prior comment on accident. For anyone confused by @bluepeter's reply to seemingly no-one, I posted about the an API event in an AWS:Serverless:Function with a path of !Join [ !Ref ApiBaseUrl, /something ] failing to transform on CloudFormation, but running fine in aws-sam-local and validating locally.
Anyway, I do not see anyone mentioning that shorthand isn't supported except you. The documentation doesn't mention it either, and the pending documentation update (#290) indicates that Events in AWS:Serverless:Function should support all intrinsic functions. Our team is using the same !Join & !Ref shorthand combo as above to set Policies and some other values in our serverless functions without issue, so that's why I'm surprised to hit a wall with Path.
With Path property of Events structure, SAM needs to insert the value of this property into Swagger as a key of a dictionary like this:
{
"paths": {
"<Value of Path property>": {...}
}
}
Since SAM runs "before" any intrinsic functions are processed, it has no way of getting the path string that you expect to be obtained by resolving the intrinsics. SAM works around this problem in most cases by carefully passing the value (containing intrinsics) directly to the next stage of processing that deploys the stack. In case of Path, we need cannot insert an intrinsic function as a key of a dictionary. Therefore SAM gives up and fails. Policies, on the other hand, are never entirely resolved in SAM. They are passed through directly to the next layer if SAM finds an intrinsic function there.
in usage plan defintion AWS::ApiGateway::UsagePlan...not able to refer stage name from AWS::Serverless::Api...getting into race situation the usageplan ran ahead of api/stage creation...event i marked dependson:api resource for usageplan resource...but still it is not working
On Tue, 24 Apr 2018, 18:34 Pete Wildsmith, ***@***.***> wrote:
As noted repeatedly in this thread, you must use the fullly qualified name
of the Sub function, Fn::Sub, not the shorthand !Sub
On Tue, 24 Apr 2018, 13:16 Bruno Fitas, ***@***.***> wrote:
> Hi guys.
> I still have problems with Fn::ImportValue and SAM Local.
> The following deploys but I'm unable to invoke it locally.
>
> Environment:
> Variables:
> TOPIC_ARN:
> Fn::ImportValue:
> !Sub "${AlarmNotificationTopicStackName}-TopicName"
>
> Any ideas?
> Thanks
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#22 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ACz40JUgbsOQVpwkQVdLTpOd1Oko_gr5ks5trxe6gaJpZM4K7Jk_>
> .
>
Activity
deathbob commentedon Nov 29, 2016
Trying to use
!GetAttfor SecurityGroupIds in a VpcConfig section of a Lambda, getType of property 'VpcConfig' is invalid.Works fine when I manually look up the values and plug in the strings, so figure it must be this same issue.
Timeframe on a fix? Any workarounds possible?
Loving the new SAM stuff but this is a deal-breaker.
sanathkr commentedon Nov 29, 2016
I am sorry you are running into the bug. Unfortunately there are no workarounds besides switching to regular AWS::Lambda::Function resource.
We are actively working on fixing it. Will let you know once its done
stuartstevenson commentedon Dec 15, 2016
I've been having this issue with
Fn::ImportValuefor the ::Api Variables property to be able to pass in the function arn.Is this bug fix to support all of the intrinsic functions?
sanathkr commentedon Dec 15, 2016
@stuartstevenson #20 was a bug that was fixed. You should be able to use any Fn:: function with Variables property. However you cannot pass the ARN directly to your Swagger. It doesn't work. You should pass function name and construct the ARN there. See this example: https://github.com/awslabs/serverless-application-model/blob/master/examples/2016-10-31/api_swagger_cors/swagger.yaml#L23
joekiller commentedon Dec 15, 2016
Fn::Importwasn't working for.me earlier today. Can you all confirm that it is fixed? I can create an example if necessary.sanathkr commentedon Dec 15, 2016
Can you give me an example with the error you received?
joekiller commentedon Dec 15, 2016
I'll create one tomorrow and post here.
stuartstevenson commentedon Dec 16, 2016
@sanathkr Thank you for your response. Is there a reason why ARNs in particular cannot be passed as I had made the assumption that the stage variable was just a string i was setting? I would not have assumed that the contents of the string would be validated.
joekiller commentedon Dec 16, 2016
I was using multiple short form functions in a row which is not supported. So trying
Is improper while
Works. http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-base64.html Notes the problem I had.
brettstack commentedon Dec 21, 2016
I'm still getting this error when trying to use
!ImportValueforAWS::Serverless::Functionweargoggles commentedon Jan 19, 2017
I'm experiencing a variation of this trying to use !Ref as a value in a Function's Environment. Is my only option to switch to AWS::Lambda::Function for now?
Edit: I had a typo in my CodeUri attribute and that caused "internal error in transform" which led me here. Sorry.
sanathkr commentedon Jan 25, 2017
!Ref in environment variables is supposed to work out-of-box. Can you post an example?
weargoggles commentedon Jan 25, 2017
It did work. I was mistaken.
jolexa commentedon Feb 9, 2017
Our org would also like to see
!Refsupported in a theCodeUrifield of aAWS::Serverless::Functionin addition to the proposed items in the original comment.Something like this, is what we are thinking (idolized design):
11 remaining items
aaronp-hd commentedon Feb 5, 2018
@bluepeter Ah right, I didn't realise that was the case. I have the If part working now. Thanks a lot for your help!
MaiKaY commentedon Feb 5, 2018
@eelixa would be cool if you can paste your working code here. To avoid similar issues in the future :-)
aaronp-hd commentedon Feb 8, 2018
I ended up with something like this:
And then:
bluepeter commentedon Feb 8, 2018
You cannot use the shorthand notation in SAM. Please use, e.g.,
Fn::JoinandRefinstead. See the discussion above in this very issue.joshuahiggins commentedon Feb 8, 2018
Sorry, removed my prior comment on accident. For anyone confused by @bluepeter's reply to seemingly no-one, I posted about the an API event in an
AWS:Serverless:Functionwith a path of!Join [ !Ref ApiBaseUrl, /something ]failing to transform on CloudFormation, but running fine inaws-sam-localand validating locally.Anyway, I do not see anyone mentioning that shorthand isn't supported except you. The documentation doesn't mention it either, and the pending documentation update (#290) indicates that
EventsinAWS:Serverless:Functionshould support all intrinsic functions. Our team is using the same!Join&!Refshorthand combo as above to set Policies and some other values in our serverless functions without issue, so that's why I'm surprised to hit a wall withPath.sanathkr commentedon Feb 8, 2018
With
Pathproperty ofEventsstructure, SAM needs to insert the value of this property into Swagger as a key of a dictionary like this:Since SAM runs "before" any intrinsic functions are processed, it has no way of getting the path string that you expect to be obtained by resolving the intrinsics. SAM works around this problem in most cases by carefully passing the value (containing intrinsics) directly to the next stage of processing that deploys the stack. In case of Path, we need cannot insert an intrinsic function as a key of a dictionary. Therefore SAM gives up and fails. Policies, on the other hand, are never entirely resolved in SAM. They are passed through directly to the next layer if SAM finds an intrinsic function there.
joshuahiggins commentedon Feb 8, 2018
Good to know. Thanks for the detailed info.
anandchristal commentedon Apr 12, 2018
in usage plan defintion AWS::ApiGateway::UsagePlan...not able to refer stage name from AWS::Serverless::Api...getting into race situation the usageplan ran ahead of api/stage creation...event i marked dependson:api resource for usageplan resource...but still it is not working
brunofitas commentedon Apr 24, 2018
Hi guys.
I still have problems with Fn::ImportValue and SAM Local.
The following deploys but I'm unable to invoke it locally.
Any ideas?
Thanks
weargoggles commentedon Apr 24, 2018
weargoggles commentedon Apr 24, 2018
OGoodness commentedon Feb 16, 2022
what's the most recent issue related to this? So that my team can track this issue.
hoffa commentedon Oct 11, 2022
@OGoodness I've created the #2533 meta-issue to track intrinsic function-related problems