在/使用CF下的API网关创建方法 [英] Create methods under / using CF for API Gateway

查看:77
本文介绍了在/使用CF下的API网关创建方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用CF在API Gateway的根目录/文件夹下创建方法?因此,例如,我有一个看起来像以下的网关:

How do I create methods under API Gateway's root / folder using CF? So for example I have a Gateway that looks like the following:

/
选项
POST

/ OPTIONS POST

但是当尝试使用CF时,我得到:
仅资源路径部分在开头和结尾处允许使用a-zA-Z0-9 ._-和花括号。因此,我的PathPart是有问题的行。

However when trying to do that with CF I get: Resource's path part only allow a-zA-Z0-9._- and curly braces at the beginning and the end. So my PathPart is the offending line.

  ApiGate:
    Type: AWS::ApiGateway::Resource
    Properties:
      ParentId: !GetAtt 
        - ApiGateApi
        - RootResourceId
      PathPart: '{/}'
      RestApiId: !Ref ApiGateApi

我可以将PathPart更改为其他内容,但是它将其创建为/不需要的子对象。

I can change the PathPart to something else but then it creates it as a child object under / which is what I don't want.

推荐答案

将以下内容添加到我的 AWS :: ApiGateway :: Method 后,它现在可以工作了。

Turns out after adding the following to my AWS::ApiGateway::Method it works now.

  MyMethodOPTIONS:
    Type: 'AWS::ApiGateway::Method'
    Properties:
      ResourceId: !GetAtt MyRestApi.RootResourceId

在我的模板中有更多上下文:

Here is more context into my Template:

  ApiGatewayMethodOPTIONS:
    Type: 'AWS::ApiGateway::Method'
    Properties:
      ResourceId: !GetAtt ApiGatewayRestApi.RootResourceId
      RestApiId: !Ref ApiGatewayRestApi
      AuthorizationType: NONE
      HttpMethod: OPTIONS
      Integration:
        Type: MOCK
        IntegrationResponses:
          - 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: ''
            StatusCode: '200'
        PassthroughBehavior: NEVER
        RequestTemplates:
          application/json: '{"statusCode": 200}'
      MethodResponses:
        - ResponseModels:
            application/json: Empty
          ResponseParameters:
            method.response.header.Access-Control-Allow-Headers: true
            method.response.header.Access-Control-Allow-Methods: true
            method.response.header.Access-Control-Allow-Origin: true
          StatusCode: '200'



  ApiGatewayRestApi:
    Type: AWS::ApiGateway::RestApi
    Properties:
      ApiKeySourceType: HEADER
      EndpointConfiguration:
        Types:
          - REGIONAL
      Name: SearchAPI

这篇关于在/使用CF下的API网关创建方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆