Amazon web services AWS SAM部署,如何查找API网关的URL?

Amazon web services AWS SAM部署,如何查找API网关的URL?,amazon-web-services,aws-api-gateway,sam,Amazon Web Services,Aws Api Gateway,Sam,从命令行部署后,如何查找API网关的URL地址? 我使用一个类似于下面的脚本来部署API网关和授权器,它部署得很好 https://github.com/floodfx/aws-lambda-proxy-using-sam-local/blob/master/deploy.sh 我正试图找出如何在部署后从命令行获取API网关的地址 API网关被创建,我可以看到堆栈: aws cloudformation describe-stacks 必须有一个简单的命令我没有得到这一点。我刚刚有时间正确回答

从命令行部署后,如何查找API网关的URL地址?

我使用一个类似于下面的脚本来部署API网关和授权器,它部署得很好

https://github.com/floodfx/aws-lambda-proxy-using-sam-local/blob/master/deploy.sh

我正试图找出如何在部署后从命令行获取API网关的地址

API网关被创建,我可以看到堆栈:

aws cloudformation describe-stacks

必须有一个简单的命令我没有得到这一点。

我刚刚有时间正确回答。具有API网关定义:

Resources:
  ...
  ServerlessRestApi:
    Type: AWS::Serverless::Api
    DeletionPolicy: "Retain"
    Properties:
      StageName: Prod
  ...
您可以输出

Outputs:
  ProdDataEndpoint:
    Description: "API Prod stage endpoint"
    Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"

我有单独的
AWS::ApiGateway::RestApi
AWS::ApiGateway::Stage
资源,因此我的输出看起来有点不同,因为我没有/无法硬编码Stage名称:

Outputs:
  ProdEndpoint:
    Value: !Sub "https://${ApiGw}.execute-api.${AWS::Region}.amazonaws.com/${ApiGwStage}/"

Resources:
  ApiGw:
    Type: AWS::ApiGateway::RestApi
    Properties:
      Name: 'Serverless Ipsum #noServerNovember challenge'
      FailOnWarnings: true

  ApiGwDeployment:
    Type: AWS::ApiGateway::Deployment
    # Required -- see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-deployment.html
    DependsOn: ApiGwMethod
    Properties:
      RestApiId: !Ref ApiGw

  ApiGwStage:
    Type: AWS::ApiGateway::Stage
    Properties:
      DeploymentId: !Ref ApiGwDeployment
      MethodSettings:
        - DataTraceEnabled: true
          HttpMethod: '*'
          LoggingLevel: INFO
          ResourcePath: '/*'
      RestApiId: !Ref ApiGw
      StageName: prod

  ApiGwResource:
    Type: AWS::ApiGateway::Resource
    Properties:
      RestApiId: !Ref ApiGw
      ParentId: !GetAtt ["ApiGw", "RootResourceId"]
      PathPart: "{proxy+}"

  ApiGwMethod:
    Type: AWS::ApiGateway::Method
    Properties:
      RestApiId: !Ref ApiGw
      ResourceId: !Ref ApiGwResource
      HttpMethod: ANY
      AuthorizationType: NONE
      Integration:
        Type: AWS_PROXY
        IntegrationHttpMethod: POST
        Uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ServerlessIpsumFunction.Arn}/invocations"

您可以使用cloudformation模板的输出参数导出资源引用,我刚才看到了。。也许它会帮助其他人我会添加一个示例输出:示例APIURL:Value:!Sub“https://${ExampleAPI}.executeAPI.${AWS::Region}.amazonaws.com/${StageName}/”我在github上举了一些例子,如果有人仍在努力解决这个问题:如何在运行时获得该输出的值?Op指定的SAM部署(不显式创建资源)。
Outputs:
  ProdEndpoint:
    Value: !Sub "https://${ApiGw}.execute-api.${AWS::Region}.amazonaws.com/${ApiGwStage}/"

Resources:
  ApiGw:
    Type: AWS::ApiGateway::RestApi
    Properties:
      Name: 'Serverless Ipsum #noServerNovember challenge'
      FailOnWarnings: true

  ApiGwDeployment:
    Type: AWS::ApiGateway::Deployment
    # Required -- see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-deployment.html
    DependsOn: ApiGwMethod
    Properties:
      RestApiId: !Ref ApiGw

  ApiGwStage:
    Type: AWS::ApiGateway::Stage
    Properties:
      DeploymentId: !Ref ApiGwDeployment
      MethodSettings:
        - DataTraceEnabled: true
          HttpMethod: '*'
          LoggingLevel: INFO
          ResourcePath: '/*'
      RestApiId: !Ref ApiGw
      StageName: prod

  ApiGwResource:
    Type: AWS::ApiGateway::Resource
    Properties:
      RestApiId: !Ref ApiGw
      ParentId: !GetAtt ["ApiGw", "RootResourceId"]
      PathPart: "{proxy+}"

  ApiGwMethod:
    Type: AWS::ApiGateway::Method
    Properties:
      RestApiId: !Ref ApiGw
      ResourceId: !Ref ApiGwResource
      HttpMethod: ANY
      AuthorizationType: NONE
      Integration:
        Type: AWS_PROXY
        IntegrationHttpMethod: POST
        Uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ServerlessIpsumFunction.Arn}/invocations"