Как получить идентификатор ресурса для данного развернутого ресурса? - PullRequest
0 голосов
/ 13 февраля 2019

Мы создали «AWS :: Serverless :: Function» с путем «/ customer» и методом «GET».

Сейчас мы пытаемся создать «AWS :: ApiGateway ::Метод "с путем" / customer "и метод" OPTIONS "

Мы можем сделать это вручную, используя идентификатор API и идентификатор ресурса для / customer.Однако мы не хотим жестко кодировать эти идентификаторы.

Мы можем получить RestApiId, используя "$ {ServerlessRestApi}", и идентификатор ресурса Root (/), используя "$ {ServerlessRestApi.RootResourceId}", однако нам нужно/ клиенты, а не /.

"Customers" : {
      "Type" : "AWS::Serverless::Function",
      "Properties": {
        "Handler": "Cloudhouse.AWSRegistration.Core::Cloudhouse.AWSRegistration.Core.LambdaEntryPoint::FunctionHandlerAsync",
        "Runtime": "dotnetcore2.1",
        "CodeUri": "",
        "MemorySize": 256,
        "Timeout": 30,
        "Role": null,
        "Policies": [ "AWSLambdaFullAccess" ],
        "Environment" : {
          "Variables" : {
            "AuthDomain": { "Ref": "AuthDomain" },
            "Audience": { "Ref": "Audience" },
            "AllowedScopes": {"Ref": "AllowedScopes"}
          }
        },
        "Events": {
          "Registration": {
            "Type": "Api",
            "Properties": {
              "Path": "/customers",
              "Method": "GET" }
          }
        }
      }
    },
"CustomersOptionsMethod": {
        "Type": "AWS::ApiGateway::Method",
        "Properties": {
          "AuthorizationType": "NONE",
          "RestApiId": { "Fn::Sub" : "${ServerlessRestApi}" },
          "ResourceId": { "Fn::Sub": "${ServerlessRestApi.RootResourceId}" },
          "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": "'GET,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": {},
              "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
                    }
               }
               ]
             }
      }

Нам нужно изменить $ {ServerlessRestApi.RootResourceId} (/) на что-то вроде $ {ServerlessRestApi.CustomersId} (/customers).

...