how do you output api resource arns from AWS::Serv

2019-07-21 05:50发布

问题:

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:

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

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


回答2:

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