【问题标题】:how do you output api resource arns from AWS::Serverless::Function (SAM)?你如何从 AWS::Serverless::Function (SAM) 输出 api 资源 arns?
【发布时间】:2017-04-23 05:44:27
【问题描述】:

我需要访问已使用 Cloudformation SAM 模板创建和订阅的网关的 arn。

当我尝试以下操作时,我收到错误“输出块中未解决的资源依赖项 [GetResource]。”

AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 
Resources:
  TestFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: dist
      Handler: index.handler
      Events:
        GetResource:
          Type: Api
          Properties:
            Path: /path
            Method: get

Outputs:   
  ReadApi:
    Value: !Ref GetResource
    Export:
      Name: ReadApi

命令失败:/bin/sh -c aws cloudformation deploy --region "ap-southeast-2" --template-file ./serverless-output.yml --capabilities CAPABILITY_IAM --stack-name "SamTest"

创建变更集失败:Waiter ChangeSetCreateComplete 失败: 服务员遇到终端故障状态状态:FAILED。原因: 的输出块中未解决的资源依赖项 [GetResource] 模板

这样可以访问网关ref吗?

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    您可以使用!Ref ServerlessRestApi 访问隐式Rest API 资源的Id。

    SAM 中的事件生成的 API 资源可以在这里找到:https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api

    【讨论】:

      【解决方案2】:

      尝试以下方法获取资源的 api id。

      Outputs:   
         ReadApiId:
            Value: !GetAtt TestFunction.RootResourceId
            Export:
               Name: ReadApiId
      

      【讨论】:

      • 可用变量列表在哪里? (即你怎么知道使用 [Resource].RootResourceId)
      猜你喜欢
      • 2018-09-28
      • 2019-05-22
      • 2021-09-02
      • 1970-01-01
      • 2019-11-11
      • 1970-01-01
      • 2017-12-09
      • 1970-01-01
      • 2021-02-11
      相关资源
      最近更新 更多