AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 825651
Accepted
Dylan Beattie
Dylan Beattie
Asked: 2017-01-12 09:33:24 +0800 CST2017-01-12 09:33:24 +0800 CST 2017-01-12 09:33:24 +0800 CST

如何将参数传递到 Amazon CloudFormation 中的嵌套堆栈?

  • 772

我正在使用 CloudFormation 来管理 Amazon API Gateway 堆栈,并尝试(重新)使用嵌套堆栈向我的每个 HTTP 端点方法添加一个 OPTIONS 方法,以便我可以使用 CORS 标头进行响应。

这是引用嵌套堆栈的 CloudFormation 代码段:

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "AWS CloudFormation template for example HTTP endpoint",
  "Resources": {
    "MyRestApi": {
      "Type": "AWS::ApiGateway::RestApi",
      "Properties": {
        "Name": "api.example.com"
      }
    },
    "HelloResource": {
      "Type": "AWS::ApiGateway::Resource",
      "Properties": {
        "RestApiId": { "Ref": "MyRestApi" },
        "ParentId": { "Fn::GetAtt": [ "MyRestApi", "RootResourceId" ] },
        "PathPart": "hello"
      }
    },
    "GETHello": {
      "Type": "AWS::ApiGateway::Method",
      "Properties": {
        "RestApiId": { "Ref": "MyRestApi" },
        "ResourceId": { "Ref": "HelloResource" },
        "HttpMethod": "GET",
        "AuthorizationType": "NONE",
        "Integration": {
          "Type": "HTTP",
          "IntegrationHttpMethod": "GET",
          "Uri": "https://my-api-server.example.com/hello",
          "IntegrationResponses": [ { "StatusCode": "200" } ],
          "RequestParameters": { "integration.request.header.Authorization": "method.request.header.Authorization" }
        },
        "MethodResponses": [
          {
            "StatusCode": "200",
            "ResponseModels": { "text/html": "Empty" }
          }
        ],
        "RequestParameters": { "method.request.header.Authorization": true }
      }
    },
    "OPTIONSHello": {
      "Type": "AWS::CloudFormation::Stack",
      "Properties": {
        "Parameters": {
          "RestApiId": "MyRestApi",
          "ResourceId": "HelloResource"
        },
        "TemplateURL": "https://s3-eu-west-1.amazonaws.com/my-cloudformation-bucket/api-gateway-cors-headers.json"
      }
    }
  }
}

然后它引用的 CloudFormation 模板 - api-gateway-cors-headers.json - 看起来像这样:

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "AWS CloudFormation template for CORS headers,
  "Parameters": {
    "RestApiId": { "Type": "String" },
    "ResourceId": { "Type": "String" }
  },
  "Resources": {
    "CORSHeader": {
      "Type": "AWS::ApiGateway::Method",
      "Properties": {
        "AuthorizationType": "NONE",
        "RestApiId": { "Ref": "RestApiId" },
        "ResourceId": { "Ref": "ResourceId" },
        "HttpMethod": "OPTIONS",
        "Integration": {
          "IntegrationResponses": [
            {
              "StatusCode": 200,
              "ResponseParameters": {
                "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'",
                "method.response.header.Access-Control-Allow-Methods": "'POST,OPTIONS'",
                "method.response.header.Access-Control-Allow-Origin": "'*'"
              },
              "ResponseTemplates": {
                "application/json": ""
              }
            }
          ],
          "PassthroughBehavior": "WHEN_NO_MATCH",
          "RequestTemplates": { "application/json": "{\"statusCode\": 200}" },
          "Type": "MOCK"
        },
        "MethodResponses": [
          {
            "StatusCode": 200,
            "ResponseModels": {
              "application/json": "Empty"
            },
            "ResponseParameters": {
              "method.response.header.Access-Control-Allow-Headers": false,
              "method.response.header.Access-Control-Allow-Methods": false,
              "method.response.header.Access-Control-Allow-Origin": false
            }
          }
        ]
      }
    }
  }
}

问题是,我无法弄清楚如何将 RestApiId 和 ResourceId 参数从父堆栈传递到嵌套堆栈。根据我尝试的语法,我收到了三到四个不同的错误消息——最近Template format error: Unresolved resource dependencies [RestApiId, ResourceId] in the Resources block of the template一次——但找不到任何关于如何将 REST API ID 和资源 ID 传递到嵌套堆栈模板的示例。我究竟做错了什么?

amazon-web-services amazon-api-gateway amazon-cloudformation
  • 1 1 个回答
  • 9848 Views

1 个回答

  • Voted
  1. Best Answer
    M. Glatki
    2017-01-12T09:51:15+08:002017-01-12T09:51:15+08:00

    您当前正在传递字符串“MyRestApi”和“HelloResource”——而不是资源引用。而是通过它们

    "OPTIONSHello": {
          "Type": "AWS::CloudFormation::Stack",
          "Properties": {
            "Parameters": {
              "RestApiId": { "Ref": "MyRestApi" },
              "ResourceId": { "Ref": "HelloResource"}
            },
            "TemplateURL": "https://s3-eu-west-1.amazonaws.com/my-cloudformation-bucket/api-gateway-cors-headers.json"
          }
        }
    
    • 2

相关问题

  • 与 AWS 中的其他系统相比,CentOS 报告的总内存较低

  • 如何在 Amazon Linux 服务器上升级到 Java 1.8?

  • 了解 Amazon AWS 使用数据

  • 亚马逊提供的负载均衡服务体验如何?

  • ELB 中现有节点的 AWS 自动缩放问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve