首页 文章

AWS Cloudformation Cloudwatch仪表板:Ref ApiGateway Headers

提问于
浏览
1

我有一个Cloudformation模板,其API网关定义为 Headers Employee Management API . 我在为API网关定义Cloudwatch仪表板时想要引用此 Headers . 现在,我将API网关的 Headers 硬编码到仪表板指标中 . 相反,如果我能够参考API网关的 Headers 属性,那就更好了 .

下面粘贴的是Cloudformation模板的一部分,它定义了API网关和仪表板 .

API网关的Cloudformation模板:

EmployeeApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      DefinitionBody:
        swagger: "2.0"
        info:
          description: "This API allows clients to query and manage employees"
          version: "1.0.0"
          title: "Employee Management API"
          contact:
            email: "me@me.com"
        basePath: "/v1"
        tags:
        - name: "employee"
          description: "Operations related to a employee"
        schemes:
        - "https"
        paths:
          /brands:
.
.
.

API网关仪表板的Cloudformation模板

EmployeeAPIDashboard:
    Type: AWS::CloudWatch::Dashboard
    Properties:
      DashboardName: "EmployeeAPIDashboard"
      DashboardBody:
        Fn::Sub: '{
              "widgets": [
                  {
                     "type": "metric",
                     "x": 0,
                     "y": 0,
                     "width": 6,
                     "height": 6,
                     "properties": {
                         "view": "timeSeries",
                         "stacked": false,
                         "metrics": [
                             [ "AWS/ApiGateway", "IntegrationLatency", "ApiName", "Employee Management API", "Stage", "Prod", { "period": 86400, "yAxis": "right", "stat": "Sum" } ],
                             [ ".", "Count", ".", ".", ".", ".", { "period": 86400, "stat": "Sum"} ],
                             [ ".", "Latency", ".", ".", ".", ".", { "period": 86400, "yAxis": "right", "stat": "Sum"} ],
                             [ ".", "5XXError", ".", ".", ".", ".", { "period": 86400, "stat": "Sum", "color": "#FF0000" } ],
                             [ ".", "4XXError", ".", ".", ".", ".", { "period": 86400, "stat": "Sum", "color": "#FFA500" } ]
                         ],
                         "region": "us-west-2",
                         "period": 300,
                         "title": "API Gateway"
                     }
                  }
              ]
          }'

2 回答

  • -1

    截至2018年10月,这不受支持 . Return values for AWS::ApiGateway::RestApi不包括ApiName . 此外,Cloudwatch metrics for ApiGateway仅支持对ApiName进行过滤 . 我们使用的解决方法是在两个地方引用相同的堆栈参数 . 所以在你的情况下,你可以做类似的事情

    Parameters:
      MyApiName:
        Type: String
        Default: "Employee Management API"
    Resources:
      EmployeeApiGatewayApi:
        Type: AWS::Serverless::Api
          Properties:
            DefinitionBody:
              info:
                title: !Ref MyApiName
    
      EmployeeAPIDashboard:
        Type: AWS::CloudWatch::Dashboard
          Properties:
            DashboardBody:
              Fn::Sub: '{
                "widgets": [
                  {
                     "properties": {
                         "metrics": [
                             [ "ApiName", ${MyApiName} ]
    
  • 0

    我相信你可以在多个堆栈中引用Stack Output ,如下所示:

    http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-crossstackref.html

相关问题