I created CloudFormation yaml template and I need to use !GetAtt "TestLambda.Arn"
as part of !Sub
function in "AWS::ApiGateway::Method" Integration Uri:
Type: "AWS::ApiGateway::Method" Properties: RestApiId: Ref: "RestApi" ResourceId: Ref: "TestResource" HttpMethod: "GET" AuthorizationType: "NONE" Integration: Type: "AWS_PROXY" IntegrationHttpMethod: "POST" Uri: !Sub "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/[[place where I want to use !GetAtt "TestLambda.Arn"]]/invocations"
As result I want to get a value something like that:
"arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/my-endpoint-lambda/invocations"
How can I use these functions together and get the desired result?
The Fn::GetAtt intrinsic function returns the value of an attribute from a resource in the template. For more information about GetAtt return values for a particular resource, refer to the documentation for that resource in the Resource and property reference.
You can author AWS CloudFormation templates in JSON or YAML formats. We support all AWS CloudFormation features and functions for both formats, including in AWS CloudFormation Designer.
Fn::Sub. The intrinsic function Fn::Sub substitutes variables in an input string with values that you specify. In your templates, you can use this function to construct commands or outputs that include values that aren't available until you create or update a stack.
GetAtt is essentially the same as the 2nd function of Ref above, it also returns an attribute of the resource that you created within your resource, but while ref returns only a default attribute, GetAtt allows you to choose from different attributes to return.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With