首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AWS SAM部署,如何查找API网关的URL?

AWS SAM部署,如何查找API网关的URL?
EN

Stack Overflow用户
提问于 2018-06-12 17:52:19
回答 3查看 13.7K关注 0票数 18

如何在命令行部署后找到API网关的URL地址?

我使用类似于下面的脚本来部署我的API网关和Authorizer,它部署得很好。

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

我正在尝试从命令行获得API的地址

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

代码语言:javascript
复制
aws cloudformation describe-stacks
代码语言:javascript
复制
"Stacks": [
        {
            "StackId": "arn:aws:cloudformation:us-east-1:761861444952:stack/mygateway912/72100720-6e67-11e8-93e9-500c28604c4a", 
            "Description": "An example serverless \"Hello World2 \" application with a custom authorizer.", 
            "Tags": [], 
            "CreationTime": "2018-06-12T17:38:40.946Z", 
            "Capabilities": [
                "CAPABILITY_IAM"
            ], 
            "StackName": "mygateway912", 
            "NotificationARNs": [], 
            "StackStatus": "CREATE_COMPLETE", 
            "DisableRollback": false, 
            "ChangeSetId": "arn:aws:cloudformation:us-east-1:76161444952:changeSet/awscli-cloudformation-package-deploy-1528825120/352f7c7a-2870-44ea-9e7f-40d16c0015df", 
            "LastUpdatedTime": "2018-06-12T17:38:46.411Z"
        }

一定有一个简单的命令,我错过了这个。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-06-12 19:00:42

我只是有时间好好回答。具有API网关定义:

代码语言:javascript
复制
Resources:
  ...
  ServerlessRestApi:
    Type: AWS::Serverless::Api
    DeletionPolicy: "Retain"
    Properties:
      StageName: Prod
  ...

你可以输出

代码语言:javascript
复制
Outputs:
  ProdDataEndpoint:
    Description: "API Prod stage endpoint"
    Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"
票数 27
EN

Stack Overflow用户

发布于 2018-11-07 19:23:32

我有单独的AWS::ApiGateway::RestApiAWS::ApiGateway::Stage资源,所以我的输出看起来有点不同,因为我没有/不能对艺名进行硬编码:

代码语言:javascript
复制
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"
票数 11
EN

Stack Overflow用户

发布于 2022-04-18 08:04:59

我使用的是参数AppEnv

代码语言:javascript
复制
....

Parameters:
  ...

  AppEnv:
    Type: String
    Default: stage
    Description: Application environment

Resources:
  GateWayAPI:
    Type: AWS::Serverless::Api
    Properties:
      StageName: !Ref AppEnv
      ....
  UploadFileFunction:
    ....
      Events:
        UploadFile:
          ...
          Properties:
            Path: /upload-file
            Method: post
            RestApiId: !Ref GateWayAPI
....

Outputs:
 ....
  UploadFileApi:
    Description: "API Gateway endpoint URL for UploadFileFunction"
    Value: !Sub "https://${GateWayAPI}.execute-api.${AWS::Region}.amazonaws.com/${AppEnv}/upload-file/"
  ...

全配置文件

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50823039

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档