How to use Sub and GetAtt functions at the same time in CloudFormation template?
I know it's an old question, but still the first result in Google:
Parameters:
path:
Type: String
Default: something/script.sh
Resources:
Bucket:
Type: AWS::S3::Bucket
Outputs:
ScriptUrl:
Description: Script Url
Value:
Fn::Sub:
- ${url}${the_path}
- {url: !GetAtt Bucket.WebsiteURL, the_path: !Ref path}
We can use Fn::
for the nested intrinsic functions if using the !
short form first. So
!Sub "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/$(Fn::GetAtt:[TestLambda, Arn])/invocations"
You don't need to use !GetAtt
here, !Sub
will automatically unpack values for you if you place them within the place holder:
Uri: !Sub arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/${TestLambda.Arn}/invocations
This is explained in the docs:
If you specify template parameter names or resource logical IDs, such as
${InstanceTypeParameter}
, AWS CloudFormation returns the same values as if you used the Ref intrinsic function. If you specify resource attributes, such as${MyInstance.PublicIp}
, AWS CloudFormation returns the same values as if you used theFn::GetAtt
intrinsic function.