如何在CloudFormation模板中同时使用Sub和GetAtt函数? [英] How to use Sub and GetAtt functions at the same time in CloudFormation template?

查看:211
本文介绍了如何在CloudFormation模板中同时使用Sub和GetAtt函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了CloudFormation yaml模板,并且需要使用!GetAtt TestLambda.Arn 作为!Sub AWS :: ApiGateway :: Method函数中的集成Uri:

I create 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 desired result?

推荐答案

您无需在此处使用!GetAtt !Sub 会自动为您解压缩值:

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

docs


如果您指定模板参数名称或资源逻辑ID,例如 $ {InstanceTypeParameter} ,AWS CloudFormation返回与使用Ref内部函数相同的值。如果您指定资源属性,例如 $ {MyInstance.PublicIp} ,则AWS CloudFormation返回的值与使用 Fn :: GetAtt 内在函数。

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 the Fn::GetAtt intrinsic function.

这篇关于如何在CloudFormation模板中同时使用Sub和GetAtt函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆