how do you output api resource arns from AWS::Serverless::Function (SAM)?

假装没事ソ 提交于 2019-12-12 19:26:46

问题


I need to access the arn of a gateway that has been created and subscribed to using a Cloudformation SAM template.

When I try the following, I get an error 'Unresolved resource dependencies [GetResource] in the Outputs block.'

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

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

Failed to create the changeset: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state Status: FAILED. Reason: Unresolved resource dependencies [GetResource] in the Outputs block of the template

Is it possible to access the gateway ref in this way?


回答1:


You can access the Id of the implicit Rest API resource by using !Ref ServerlessRestApi.

The API resources generated by an event in SAM can be found here: https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api




回答2:


Try the following to get the api id of the resource.

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


来源:https://stackoverflow.com/questions/41031737/how-do-you-output-api-resource-arns-from-awsserverlessfunction-sam

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!