Example usage for com.amazonaws.services.apigateway.model PutMethodRequest setHttpMethod

List of usage examples for com.amazonaws.services.apigateway.model PutMethodRequest setHttpMethod

Introduction

In this page you can find the example usage for com.amazonaws.services.apigateway.model PutMethodRequest setHttpMethod.

Prototype


public void setHttpMethod(String httpMethod) 

Source Link

Document

<p> [Required] Specifies the method request's HTTP method type.

Usage

From source file:squash.deployment.lambdas.ApiGatewayCustomResourceLambda.java

License:Apache License

PutMethodResult createMethodOnResource(String methodName, String resourceId, String restApiId,
        Map<String, String> extraParameters, AmazonApiGateway client, String revvingSuffix, String region,
        LambdaLogger logger) throws IOException {
    logger.log("Creating method: " + methodName + " on resource with id: " + resourceId);
    // Short sleep - this avoids the Too Many Requests error in this
    // custom resource when creating the cloudformation stack.
    pause(logger);/*from   w  ww.  j av  a2  s .  c  o m*/
    // Variables for method request
    PutMethodRequest putMethodRequest = new PutMethodRequest();
    putMethodRequest.setAuthorizationType("None");
    putMethodRequest.setApiKeyRequired(false);
    putMethodRequest.setRestApiId(restApiId);
    putMethodRequest.setResourceId(resourceId);
    Map<String, Boolean> methodRequestParameters = new HashMap<>();

    // Variables for the happy-path method response
    PutMethodResponseRequest putMethod200ResponseRequest = new PutMethodResponseRequest();
    putMethod200ResponseRequest.setRestApiId(restApiId);
    putMethod200ResponseRequest.setResourceId(resourceId);
    putMethod200ResponseRequest.setStatusCode("200");

    // Variables for the server-error 500 method response. This response has the
    // same parameters as the 200 response.
    PutMethodResponseRequest putMethod500ResponseRequest = new PutMethodResponseRequest();
    putMethod500ResponseRequest.setRestApiId(restApiId);
    putMethod500ResponseRequest.setResourceId(resourceId);
    putMethod500ResponseRequest.setStatusCode("500");

    // Variables for the bad-request 400 method response. This response has the
    // same parameters as the 200 response.
    PutMethodResponseRequest putMethod400ResponseRequest = new PutMethodResponseRequest();
    putMethod400ResponseRequest.setRestApiId(restApiId);
    putMethod400ResponseRequest.setResourceId(resourceId);
    putMethod400ResponseRequest.setStatusCode("400");

    // Response models are used to specify the response Body schema - so we can
    // populate the values using the integration response template (when we have
    // one)
    Map<String, String> methodResponseModels = new HashMap<>();
    // Response parameters allows us to specify response headers
    Map<String, Boolean> methodResponseParameters = new HashMap<>();
    // Add CORS response headers
    methodResponseParameters.put("method.response.header.access-control-allow-headers",
            Boolean.valueOf("true"));
    methodResponseParameters.put("method.response.header.access-control-allow-methods",
            Boolean.valueOf("true"));
    methodResponseParameters.put("method.response.header.access-control-allow-origin", Boolean.valueOf("true"));
    methodResponseParameters.put("method.response.header.access-control-max-age", Boolean.valueOf("true"));

    methodResponseParameters.put("method.response.header.content-type", Boolean.valueOf("true"));
    if (!methodName.equals("OPTIONS")) {
        // Add header to prevent caching of booking pages, except for OPTIONS -
        // which is not cached.
        methodResponseParameters.put("method.response.header.cache-control", Boolean.valueOf("true"));
    }
    // Variables for integration input
    PutIntegrationRequest putIntegrationRequest = new PutIntegrationRequest();
    putIntegrationRequest.setRestApiId(restApiId);
    putIntegrationRequest.setResourceId(resourceId);
    // Request parameters follow pattern like:
    // "requestParameters" : {
    // "integration.request.path.integrationPathParam" :
    // "method.request.querystring.latitude",
    // "integration.request.querystring.integrationQueryParam" :
    // "method.request.querystring.longitude"
    // }
    Map<String, String> requestParameters = new HashMap<>();

    // Request templates follow pattern like:
    // "requestTemplates" : {
    // "application/json" : "json request template 2",
    // "application/xml" : "xml request template 2"
    // }
    Map<String, String> requestTemplates = new HashMap<>();

    // Variables for integration response
    // Configure the integration response for the happy-path case
    PutIntegrationResponseRequest putIntegration200ResponseRequest = new PutIntegrationResponseRequest();
    putIntegration200ResponseRequest.setRestApiId(restApiId);
    putIntegration200ResponseRequest.setResourceId(resourceId);
    putIntegration200ResponseRequest.setStatusCode("200");

    // Configure the integration response for the server-error 500 case. This
    // response has the same parameters as the 200 response.
    PutIntegrationResponseRequest putIntegration500ResponseRequest = new PutIntegrationResponseRequest();
    putIntegration500ResponseRequest.setRestApiId(restApiId);
    putIntegration500ResponseRequest.setResourceId(resourceId);
    putIntegration500ResponseRequest.setStatusCode("500");

    // Configure the integration response for the bad-request 400 case. This
    // response has the same parameters as the 200 response.
    PutIntegrationResponseRequest putIntegration400ResponseRequest = new PutIntegrationResponseRequest();
    putIntegration400ResponseRequest.setRestApiId(restApiId);
    putIntegration400ResponseRequest.setResourceId(resourceId);
    putIntegration400ResponseRequest.setStatusCode("400");
    // Response parameters follow pattern like:
    // "responseParameters" : {
    // "method.response.header.test-method-response-header" :
    // "integration.response.header.integrationResponseHeaderParam1"
    // }
    Map<String, String> responseParameters = new HashMap<>();
    // Add CORS response headers to all method responses
    responseParameters.put("method.response.header.access-control-allow-headers",
            "'content-type,x-amz-date,authorization,accept,x-amz-security-token,location,cache-control'");
    responseParameters.put("method.response.header.access-control-allow-origin", "'*'");
    // This will reduce preflight calls...
    responseParameters.put("method.response.header.access-control-max-age", "'86400'");

    responseParameters.put("method.response.header.content-type", "'text/html; charset=utf-8'");

    // Add no-cache header except to options methods
    if (!methodName.contains("OPTIONS")) {
        responseParameters.put("method.response.header.cache-control", "'no-cache, must-revalidate'");
    }

    // Response templates follow pattern like:
    // "responseTemplates" : {
    // "application/json" : "json 200 response template",
    // "application/xml" : "xml 200 response template"
    // }
    // The response template to use will be chosen by Apigateway based on e.g.
    // the Accept header in the client's request.
    Map<String, String> response200Templates = new HashMap<>();
    Map<String, String> response500Templates = new HashMap<>();
    Map<String, String> response400Templates = new HashMap<>();
    // Set as default response unless covered by other
    // PutIntegrationResponseInput-s
    putIntegration200ResponseRequest.setSelectionPattern(".*");

    // N.B. For now we encode the redirect Url after an error as part of the
    // errorMessage in exceptions thrown from Lambda. The templates below then
    // parse this Url out from the errorMessage, display the message alone for a
    // short time, then go to the redirect Url.
    String errorResponseMappingTemplate = "#set($inputRoot = $input.path('$'))\n"
            + "#set($httpIndex = $inputRoot.errorMessage.lastIndexOf('http'))\n"
            + "#set($redirectUrl = $inputRoot.errorMessage.substring($httpIndex))\n" + "<head>\n"
            + "<title>Grrr</title>\n" + "<meta http-equiv=\"refresh\" content=\"5;URL='$redirectUrl'\" />\n"
            + "</head>\n" + "<body>\n" + "$inputRoot.errorMessage.substring(0, $httpIndex)\n"
            + "<p align='left'>\n"
            + "<a href= '$redirectUrl'>Please click here if you are not redirected automatically within a few seconds</a>\n"
            + "</p>\n" + "</body>\n";

    // The PUT and DELETE lambda methods currently use the Cognito context
    // variables to determine whether the caller was authenticated as admin.
    // This template just adds these Cognito variables to the others
    // already present in the request body.
    // N.B. We add the request id to the body of all integration requests to
    // allow end-to-end tracing of calls - see, e.g.,
    // https://aws.amazon.com/blogs/compute/techniques-and-tools-for-better-serverless-api-logging-with-amazon-api-gateway-and-aws-lambda/
    // (In short: the browser response when it calls apiGateway has a
    // x-amzn-RequestId header with this request id, allowing tracing the call
    // from the browser right through to lambda.)
    String bookingsPutDeleteRequestTemplate = "{\n" + "\"requestId\" : \"$context.requestId\",\n"
            + "\"apiGatewayBaseUrl\" : $input.json('$.apiGatewayBaseUrl'),\n"
            + "\"court\" : $input.json('$.court'),\n" + "\"courtSpan\" : $input.json('$.courtSpan'),\n"
            + "\"slot\" : $input.json('$.slot'),\n" + "\"slotSpan\" : $input.json('$.slotSpan'),\n"
            + "\"date\" : $input.json('$.date'),\n" + "\"password\" : $input.json('$.password'),\n"
            + "\"name\" : $input.json('$.name'),\n" + "\"putOrDelete\" : $input.json('$.putOrDelete'),\n"
            + "\"redirectUrl\" : $input.json('$.redirectUrl'),\n"
            + "\"cognitoAuthenticationType\" : \"$context.identity.cognitoAuthenticationType\",\n"
            + "\"cognitoIdentityPoolId\" : \"$context.identity.cognitoIdentityPoolId\"\n" + "}";

    String bookingRulesPutDeleteRequestTemplate = "{\n" + "\"requestId\" : \"$context.requestId\",\n"
            + "\"bookingRule\" : $input.json('$.bookingRule'),\n"
            + "\"dateToExclude\" : $input.json('$.dateToExclude'),\n"
            + "\"putOrDelete\" : $input.json('$.putOrDelete'),\n"
            + "\"cognitoAuthenticationType\" : \"$context.identity.cognitoAuthenticationType\",\n"
            + "\"cognitoIdentityPoolId\" : \"$context.identity.cognitoIdentityPoolId\"\n" + "}";

    PutMethodResult method = null;
    if (methodName.equals("ValidDatesGET")) {
        putMethodRequest.setHttpMethod("GET");
        putMethod200ResponseRequest.setHttpMethod("GET");
        putIntegration200ResponseRequest.setHttpMethod("GET");
        putMethod500ResponseRequest.setHttpMethod("GET");
        putIntegration500ResponseRequest.setHttpMethod("GET");
        method = client.putMethod(putMethodRequest);
        // N.B. Using LAMBDA type here is not yet supported by this sdk - so use
        // AWS instead.
        putIntegrationRequest.setType(IntegrationType.AWS);
        putIntegrationRequest.setUri(extraParameters.get("ValidDatesGETLambdaURI"));
        // N.B. Lambda uses POST even for GET methods
        putIntegrationRequest.setHttpMethod("GET");
        putIntegrationRequest.setCredentials(extraParameters.get("BookingsApiGatewayInvocationRole"));
        response200Templates.put("application/json",
                "#set($inputRoot = $input.path('$'))\n" + "{\"requestId\" : \"$context.requestId\",\n"
                        + "\"dates\": " + "#foreach($elem in $inputRoot)\n" + "    $elem\n"
                        + "#if($foreach.hasNext),#end\n" + "#end\n" + "}");
        response500Templates.put("application/json", errorResponseMappingTemplate);
        responseParameters.put("method.response.header.access-control-allow-methods", "'GET,OPTIONS'");

        // Lambda exception message regex that we want mapped to the 500 response
        // .*The booking name.*|.*password.*
        putIntegration500ResponseRequest
                .setSelectionPattern("Apologies - something has gone wrong. Please try again.");
    } else if (methodName.equals("ValidDatesOPTIONS")) {
        // OPTIONS method is required for CORS.
        putMethodRequest.setHttpMethod("OPTIONS");
        putMethod200ResponseRequest.setHttpMethod("OPTIONS");
        putIntegration200ResponseRequest.setHttpMethod("OPTIONS");
        method = client.putMethod(putMethodRequest);
        putIntegrationRequest.setType(IntegrationType.MOCK);
        putIntegrationRequest.setHttpMethod("OPTIONS");
        requestTemplates.put("application/json", "{\"statusCode\": 200}");
        responseParameters.put("method.response.header.access-control-allow-methods", "'GET,OPTIONS'");
    } else if (methodName.equals("BookingsGET")) {
        methodRequestParameters.put("method.request.querystring.date", Boolean.valueOf("true"));
        putMethodRequest.setRequestParameters(methodRequestParameters);
        putMethodRequest.setHttpMethod("GET");
        putMethod200ResponseRequest.setHttpMethod("GET");
        putMethod500ResponseRequest.setHttpMethod("GET");
        putMethod400ResponseRequest.setHttpMethod("GET");
        putIntegration500ResponseRequest.setHttpMethod("GET");
        putIntegration200ResponseRequest.setHttpMethod("GET");
        putIntegration400ResponseRequest.setHttpMethod("GET");

        method = client.putMethod(putMethodRequest);
        // N.B. Using LAMBDA type here is not yet supported by this sdk - so use
        // AWS instead.
        putIntegrationRequest.setType(IntegrationType.AWS);
        putIntegrationRequest.setUri(extraParameters.get("BookingsGETLambdaURI"));
        // N.B. Lambda uses POST even for GET methods
        putIntegrationRequest.setHttpMethod("GET");
        putIntegrationRequest.setCredentials(extraParameters.get("BookingsApiGatewayInvocationRole"));
        requestTemplates.put("application/json",
                "#set($inputRoot = $input.path('$'))\n" + "{\n" + "\"requestId\" : \"$context.requestId\",\n"
                        + "\"date\" : \"$input.params('date')\",\n" + "\"redirectUrl\" : \"http://"
                        + squashWebsiteBucket + ".s3-website-" + region
                        + ".amazonaws.com?selectedDate=${input.params('date')}.html\"\n" + "}");
        responseParameters.put("method.response.header.access-control-allow-methods",
                "'GET,PUT,DELETE,POST,OPTIONS'");
        putIntegration500ResponseRequest
                .setSelectionPattern("Apologies - something has gone wrong. Please try again.");
        putIntegration400ResponseRequest
                .setSelectionPattern("The booking date.*|Cannot access bookings or rules.*");
        responseParameters.put("method.response.header.content-type", "'application/json'");
    } else if (methodName.equals("BookingsPUT")) {
        putMethodRequest.setHttpMethod("PUT");
        // Set IAM authorisation so ApiGateway provides the Cognito context
        // variables
        putMethodRequest.setAuthorizationType("AWS_IAM");
        putMethod200ResponseRequest.setHttpMethod("PUT");
        putMethod500ResponseRequest.setHttpMethod("PUT");
        putMethod400ResponseRequest.setHttpMethod("PUT");
        putIntegration500ResponseRequest.setHttpMethod("PUT");
        putIntegration200ResponseRequest.setHttpMethod("PUT");
        putIntegration400ResponseRequest.setHttpMethod("PUT");
        method = client.putMethod(putMethodRequest);
        // N.B. Using LAMBDA type here is not yet supported by this sdk - so use
        // AWS instead.
        putIntegrationRequest.setType(IntegrationType.AWS);
        putIntegrationRequest.setUri(extraParameters.get("BookingsPUTDELETELambdaURI"));
        // N.B. Lambda uses POST even for GET methods
        putIntegrationRequest.setHttpMethod("PUT");
        putIntegrationRequest.setCredentials(extraParameters.get("BookingsApiGatewayInvocationRole"));
        requestTemplates.put("application/json", bookingsPutDeleteRequestTemplate);
        responseParameters.put("method.response.header.access-control-allow-methods",
                "'GET,PUT,DELETE,POST,OPTIONS'");
        putIntegration500ResponseRequest
                .setSelectionPattern("Apologies - something has gone wrong. Please try again.");
        putIntegration400ResponseRequest.setSelectionPattern(
                "The booking court.*|The booking time.*|The booking name.*|The booking date.*|The password is incorrect.*|You must login to manage block bookings.*|Booking creation failed.*|Booking cancellation failed.*|Cannot mutate bookings or rules.*|Cannot access bookings or rules.*");
        responseParameters.put("method.response.header.content-type", "'application/json'");
    } else if (methodName.equals("BookingsDELETE")) {
        putMethodRequest.setHttpMethod("DELETE");
        // Set IAM authorisation so ApiGateway provides the Cognito context
        // variables
        putMethodRequest.setAuthorizationType("AWS_IAM");
        putMethod200ResponseRequest.setHttpMethod("DELETE");
        putMethod500ResponseRequest.setHttpMethod("DELETE");
        putMethod400ResponseRequest.setHttpMethod("DELETE");
        putIntegration500ResponseRequest.setHttpMethod("DELETE");
        putIntegration200ResponseRequest.setHttpMethod("DELETE");
        putIntegration400ResponseRequest.setHttpMethod("DELETE");
        method = client.putMethod(putMethodRequest);
        // N.B. Using LAMBDA type here is not yet supported by this sdk - so use
        // AWS instead.
        putIntegrationRequest.setType(IntegrationType.AWS);
        putIntegrationRequest.setUri(extraParameters.get("BookingsPUTDELETELambdaURI"));
        // N.B. Lambda uses POST even for GET methods
        putIntegrationRequest.setHttpMethod("DELETE");
        putIntegrationRequest.setCredentials(extraParameters.get("BookingsApiGatewayInvocationRole"));
        requestTemplates.put("application/json", bookingsPutDeleteRequestTemplate);
        responseParameters.put("method.response.header.access-control-allow-methods",
                "'GET,PUT,DELETE,POST,OPTIONS'");
        putIntegration500ResponseRequest.setSelectionPattern(
                "Apologies - something has gone wrong. Please try again.|Booking creation failed.*|Booking cancellation failed.*|Cannot mutate bookings or rules.*|Cannot access bookings or rules.*");
        putIntegration400ResponseRequest.setSelectionPattern(
                "The booking court.*|The booking time.*|The booking name.*|The booking date.*|The password is incorrect.*|You must login to manage block bookings.*");
        responseParameters.put("method.response.header.content-type", "'application/json'");
    } else if (methodName.equals("BookingsPOST")) {
        // Redirect to the mutated booking page after creating or cancelling a
        // booking
        putMethod200ResponseRequest.setStatusCode("303");
        putMethodRequest.setHttpMethod("POST");
        putMethod500ResponseRequest.setHttpMethod("POST");
        putMethod400ResponseRequest.setHttpMethod("POST");
        putIntegration500ResponseRequest.setHttpMethod("POST");
        putMethod200ResponseRequest.setHttpMethod("POST");
        putIntegration400ResponseRequest.setHttpMethod("POST");
        // Define the 303 integration response (which by default will match any
        // response from lambda)
        putIntegration200ResponseRequest.setStatusCode("303");
        putIntegration200ResponseRequest.setHttpMethod("POST");
        method = client.putMethod(putMethodRequest);
        // N.B. Using LAMBDA type here is not yet supported by this sdk - so use
        // AWS instead.
        putIntegrationRequest.setType(IntegrationType.AWS);
        putIntegrationRequest.setUri(extraParameters.get("BookingsPUTDELETELambdaURI"));
        // N.B. Lambda uses POST even for GET methods
        putIntegrationRequest.setHttpMethod("POST");
        putIntegrationRequest.setCredentials(extraParameters.get("BookingsApiGatewayInvocationRole"));
        response500Templates.put("application/json", errorResponseMappingTemplate);
        response400Templates.put("application/json", errorResponseMappingTemplate);
        // Need to convert html-post body from url-encoded string to json (which
        // lambda likes)
        requestTemplates.put("application/x-www-form-urlencoded", getBookingPostRequestTemplate(logger));
        responseParameters.put("method.response.header.access-control-allow-methods",
                "'GET,PUT,DELETE,POST,OPTIONS'");
        methodResponseParameters.put("method.response.header.location", Boolean.valueOf("true"));
        // Redirect to the newly-mutated booking page in S3 if we have it in the
        // json from our lambda function which will have put the appropriate
        // redirectUrl into the body, unless there was an error. Recognised
        // errors should have a redirectUrl appended to the error message by my
        // lambdas(and so be handled by other status codes above). For errors I'm
        // not expecting, there will be no redirectUrl in the json from lambda.
        // In this last case, the template below will insert its own redirectUrl
        // into the body pointing to today's page - as a last-ditch failsafe.
        response200Templates.put("application/json",
                "## Use quotes to get body into a string here (input.path('$') by itself would create a POJO in error cases)\n"
                        + "#set($lambdaBody = \"$input.path('$')\")\n"
                        + "#set($countRedirects = $lambdaBody.length() - $lambdaBody.replace(\"redirectUrl\", \"\").length())\n"
                        + "#if ($countRedirects != 0)\n"
                        + "## Success case with a redirectUrl - the Location header mapping will find it.\n"
                        + "## But just in case not, put in some redirecting html also.\n"
                        + "#set($redirectUrl = $input.path('$.redirectUrl'))\n" + "#else\n"
                        + "## Unhandled error case: no redirect url from lambda, the Location header mapping will thus not find it.\n"
                        + "## We thus need to redirect to today's page by providing suitable html instead\n"
                        + "#set($redirectUrl = \"http://" + squashWebsiteBucket + ".s3-website-" + region
                        + ".amazonaws.com/today.html\")\n" + "#end\n" + "<head>\n" + "<title>Grrr</title>\n"
                        + "<meta http-equiv=\"refresh\" content=\"5;URL='$redirectUrl'\" />\n" + "</head>\n"
                        + "<body>\n" + "Apologies - something has gone wrong. Please try again.\n"
                        + "<p align='left'>\n"
                        + "<a href= '$redirectUrl'>Please click here if you are not redirected automatically within a few seconds</a>\n"
                        + "</p>\n" + "</body>\n");
        responseParameters.put("method.response.header.location", "integration.response.body.redirectUrl");
        putIntegration500ResponseRequest.setSelectionPattern(
                "Apologies - something has gone wrong. Please try again.|Booking creation failed.*|Booking cancellation failed.*|Cannot mutate bookings or rules.*|Cannot access bookings or rules.*");
        putIntegration400ResponseRequest.setSelectionPattern(
                "The booking court.*|The booking time.*|The booking name.*|The booking date.*|The password is incorrect.*");
    } else if (methodName.equals("BookingsOPTIONS")) {
        // OPTIONS method is required for CORS.
        putMethodRequest.setHttpMethod("OPTIONS");
        putMethod200ResponseRequest.setHttpMethod("OPTIONS");
        putIntegration200ResponseRequest.setHttpMethod("OPTIONS");
        method = client.putMethod(putMethodRequest);
        putIntegrationRequest.setType(IntegrationType.MOCK);
        putIntegrationRequest.setHttpMethod("OPTIONS");
        requestTemplates.put("application/json", "{\"statusCode\": 200}");
        responseParameters.put("method.response.header.access-control-allow-methods",
                "'GET,PUT,DELETE,POST,OPTIONS'");
    } else if (methodName.equals("BookingrulesGET")) {
        putMethodRequest.setHttpMethod("GET");
        putMethod200ResponseRequest.setHttpMethod("GET");
        putMethod500ResponseRequest.setHttpMethod("GET");
        putMethod400ResponseRequest.setHttpMethod("GET");
        putIntegration500ResponseRequest.setHttpMethod("GET");
        putIntegration200ResponseRequest.setHttpMethod("GET");
        putIntegration400ResponseRequest.setHttpMethod("GET");

        method = client.putMethod(putMethodRequest);
        // N.B. Using LAMBDA type here is not yet supported by this sdk - so use
        // AWS instead.
        putIntegrationRequest.setType(IntegrationType.AWS);
        putIntegrationRequest.setUri(extraParameters.get("BookingRulesGETLambdaURI"));
        // N.B. Lambda uses POST even for GET methods
        putIntegrationRequest.setHttpMethod("GET");
        putIntegrationRequest.setCredentials(extraParameters.get("BookingsApiGatewayInvocationRole"));
        requestTemplates.put("application/json", "{\"requestId\" : \"$context.requestId\"}");
        responseParameters.put("method.response.header.access-control-allow-methods",
                "'GET,PUT,DELETE,OPTIONS'");
        putIntegration500ResponseRequest.setSelectionPattern(
                "Apologies - something has gone wrong. Please try again.|Cannot mutate bookings or rules.*|Cannot access bookings or rules.*");
        responseParameters.put("method.response.header.content-type", "'application/json'");
    } else if (methodName.equals("BookingrulesPUT")) {
        putMethodRequest.setHttpMethod("PUT");
        // Set IAM authorisation so ApiGateway provides the Cognito context
        // variables
        putMethodRequest.setAuthorizationType("AWS_IAM");
        putMethod200ResponseRequest.setHttpMethod("PUT");
        putMethod500ResponseRequest.setHttpMethod("PUT");
        putMethod400ResponseRequest.setHttpMethod("PUT");
        putIntegration500ResponseRequest.setHttpMethod("PUT");
        putIntegration200ResponseRequest.setHttpMethod("PUT");
        putIntegration400ResponseRequest.setHttpMethod("PUT");
        method = client.putMethod(putMethodRequest);
        // N.B. Using LAMBDA type here is not yet supported by this sdk - so use
        // AWS instead.
        putIntegrationRequest.setType(IntegrationType.AWS);
        putIntegrationRequest.setUri(extraParameters.get("BookingRulesPUTDELETELambdaURI"));
        // N.B. Lambda uses POST even for GET methods
        putIntegrationRequest.setHttpMethod("PUT");
        putIntegrationRequest.setCredentials(extraParameters.get("BookingsApiGatewayInvocationRole"));
        requestTemplates.put("application/json", bookingRulesPutDeleteRequestTemplate);
        responseParameters.put("method.response.header.access-control-allow-methods",
                "'GET,PUT,DELETE,OPTIONS'");
        putIntegration500ResponseRequest.setSelectionPattern(
                "Apologies - something has gone wrong. Please try again.|Cannot mutate bookings or rules.*|Cannot access bookings or rules.*");
        putIntegration400ResponseRequest.setSelectionPattern(
                "You must login to manage booking rules.*|Booking rule creation failed.*|Booking rule addition failed - too many rules.*|Booking rule exclusion addition failed - too many exclusions.*|Booking rule creation failed - new rule would clash.*");
        responseParameters.put("method.response.header.content-type", "'application/json'");
    } else if (methodName.equals("BookingrulesDELETE")) {
        putMethodRequest.setHttpMethod("DELETE");
        // Set IAM authorisation so ApiGateway provides the Cognito context
        // variables
        putMethodRequest.setAuthorizationType("AWS_IAM");
        putMethod200ResponseRequest.setHttpMethod("DELETE");
        putMethod500ResponseRequest.setHttpMethod("DELETE");
        putMethod400ResponseRequest.setHttpMethod("DELETE");
        putIntegration500ResponseRequest.setHttpMethod("DELETE");
        putIntegration200ResponseRequest.setHttpMethod("DELETE");
        putIntegration400ResponseRequest.setHttpMethod("DELETE");
        method = client.putMethod(putMethodRequest);
        // N.B. Using LAMBDA type here is not yet supported by this sdk - so use
        // AWS instead.
        putIntegrationRequest.setType(IntegrationType.AWS);
        putIntegrationRequest.setUri(extraParameters.get("BookingRulesPUTDELETELambdaURI"));
        // N.B. Lambda uses POST even for GET methods
        putIntegrationRequest.setHttpMethod("DELETE");
        putIntegrationRequest.setCredentials(extraParameters.get("BookingsApiGatewayInvocationRole"));
        requestTemplates.put("application/json", bookingRulesPutDeleteRequestTemplate);
        responseParameters.put("method.response.header.access-control-allow-methods",
                "'GET,PUT,DELETE,OPTIONS'");
        putIntegration500ResponseRequest.setSelectionPattern(
                "Apologies - something has gone wrong. Please try again.|Cannot mutate bookings or rules.*|Cannot access bookings or rules.*");
        putIntegration400ResponseRequest.setSelectionPattern(
                "You must login to manage booking rules.*|Booking rule deletion failed.*|Booking rule exclusion deletion failed - latent clash exists.*");
        responseParameters.put("method.response.header.content-type", "'application/json'");
    } else if (methodName.equals("BookingrulesOPTIONS")) {
        // OPTIONS method is required for CORS.
        putMethodRequest.setHttpMethod("OPTIONS");
        putMethod200ResponseRequest.setHttpMethod("OPTIONS");
        putIntegration200ResponseRequest.setHttpMethod("OPTIONS");
        method = client.putMethod(putMethodRequest);
        putIntegrationRequest.setType(IntegrationType.MOCK);
        putIntegrationRequest.setHttpMethod("OPTIONS");
        requestTemplates.put("application/json", "{\"statusCode\": 200}");
        responseParameters.put("method.response.header.access-control-allow-methods",
                "'GET,PUT,DELETE,OPTIONS'");
    } else if (methodName.equals("ReservationformGET")) {
        methodRequestParameters.put("method.request.querystring.court", Boolean.valueOf("true"));
        methodRequestParameters.put("method.request.querystring.slot", Boolean.valueOf("true"));
        methodRequestParameters.put("method.request.querystring.slotLong", Boolean.valueOf("true"));
        methodRequestParameters.put("method.request.querystring.date", Boolean.valueOf("true"));
        methodRequestParameters.put("method.request.querystring.dateLong", Boolean.valueOf("true"));
        putMethodRequest.setRequestParameters(methodRequestParameters);
        putMethodRequest.setHttpMethod("GET");
        putMethod200ResponseRequest.setHttpMethod("GET");
        putIntegration200ResponseRequest.setHttpMethod("GET");
        method = client.putMethod(putMethodRequest);
        putIntegrationRequest.setType(IntegrationType.MOCK);
        putIntegrationRequest.setHttpMethod("GET");

        requestTemplates.put("application/json", "{\"statusCode\": 200}");
        response200Templates.put("text/html",
                getReservationformResponseTemplate(revvingSuffix, region, logger));
        responseParameters.put("method.response.header.access-control-allow-methods", "'GET,OPTIONS'");
    } else if (methodName.equals("ReservationformOPTIONS")) {
        // OPTIONS method is required for CORS.
        putMethodRequest.setHttpMethod("OPTIONS");
        putMethod200ResponseRequest.setHttpMethod("OPTIONS");
        putIntegration200ResponseRequest.setHttpMethod("OPTIONS");
        method = client.putMethod(putMethodRequest);
        putIntegrationRequest.setType(IntegrationType.MOCK);
        putIntegrationRequest.setHttpMethod("OPTIONS");
        requestTemplates.put("application/json", "{\"statusCode\": 200}");
        responseParameters.put("method.response.header.access-control-allow-methods", "'GET,OPTIONS'");
    } else if (methodName.equals("CancellationformGET")) {
        methodRequestParameters.put("method.request.querystring.court", Boolean.valueOf("true"));
        methodRequestParameters.put("method.request.querystring.slot", Boolean.valueOf("true"));
        methodRequestParameters.put("method.request.querystring.slotLong", Boolean.valueOf("true"));
        methodRequestParameters.put("method.request.querystring.name", Boolean.valueOf("true"));
        methodRequestParameters.put("method.request.querystring.date", Boolean.valueOf("true"));
        methodRequestParameters.put("method.request.querystring.dateLong", Boolean.valueOf("true"));
        putMethodRequest.setRequestParameters(methodRequestParameters);
        putMethodRequest.setHttpMethod("GET");
        putMethod200ResponseRequest.setHttpMethod("GET");
        putIntegration200ResponseRequest.setHttpMethod("GET");
        method = client.putMethod(putMethodRequest);
        putIntegrationRequest.setType(IntegrationType.MOCK);
        putIntegrationRequest.setHttpMethod("GET");
        requestTemplates.put("application/json", "{\"statusCode\": 200}");
        response200Templates.put("text/html",
                getCancellationformResponseTemplate(revvingSuffix, region, logger));
        responseParameters.put("method.response.header.access-control-allow-methods", "'GET,OPTIONS'");
    } else if (methodName.equals("CancellationformOPTIONS")) {
        // OPTIONS method is required for CORS.
        putMethodRequest.setHttpMethod("OPTIONS");
        putMethod200ResponseRequest.setHttpMethod("OPTIONS");
        putIntegration200ResponseRequest.setHttpMethod("OPTIONS");
        method = client.putMethod(putMethodRequest);
        putIntegrationRequest.setType(IntegrationType.MOCK);
        putIntegrationRequest.setHttpMethod("OPTIONS");
        requestTemplates.put("application/json", "{\"statusCode\": 200}");
        responseParameters.put("method.response.header.access-control-allow-methods", "'GET,OPTIONS'");
    } else {
        throw new InvalidArgumentException("Invalid method name: " + methodName);
    }

    // Method response
    putMethod200ResponseRequest.setResponseModels(methodResponseModels);
    putMethod200ResponseRequest.setResponseParameters(methodResponseParameters);
    client.putMethodResponse(putMethod200ResponseRequest);
    // Integration input
    putIntegrationRequest.setRequestParameters(requestParameters);
    putIntegrationRequest.setRequestTemplates(requestTemplates);
    putIntegrationRequest.setIntegrationHttpMethod("POST");
    client.putIntegration(putIntegrationRequest);
    // Integration response
    putIntegration200ResponseRequest.setResponseParameters(responseParameters);
    putIntegration200ResponseRequest.setResponseTemplates(response200Templates);
    putIntegration200ResponseRequest.setSelectionPattern(".*");
    client.putIntegrationResponse(putIntegration200ResponseRequest);

    if (methodName.equals("ValidDatesGET")) {
        putMethod500ResponseRequest.setResponseModels(methodResponseModels);
        putMethod500ResponseRequest.setResponseParameters(methodResponseParameters);
        client.putMethodResponse(putMethod500ResponseRequest);
        putIntegration500ResponseRequest.setResponseParameters(responseParameters);
        putIntegration500ResponseRequest.setResponseTemplates(response500Templates);
        client.putIntegrationResponse(putIntegration500ResponseRequest);
    } else if (methodName.equals("BookingsGET") || methodName.equals("BookingsPUT")
            || methodName.equals("BookingsPOST") || methodName.equals("BookingsDELETE")
            || methodName.equals("BookingrulesGET") || methodName.equals("BookingrulesPUT")
            || methodName.equals("BookingrulesDELETE")) {
        putMethod500ResponseRequest.setResponseModels(methodResponseModels);
        putMethod500ResponseRequest.setResponseParameters(methodResponseParameters);
        client.putMethodResponse(putMethod500ResponseRequest);
        putMethod400ResponseRequest.setResponseModels(methodResponseModels);
        putMethod400ResponseRequest.setResponseParameters(methodResponseParameters);
        client.putMethodResponse(putMethod400ResponseRequest);
        putIntegration500ResponseRequest.setResponseParameters(responseParameters);
        putIntegration500ResponseRequest.setResponseTemplates(response500Templates);
        client.putIntegrationResponse(putIntegration500ResponseRequest);
        putIntegration400ResponseRequest.setResponseParameters(responseParameters);
        putIntegration400ResponseRequest.setResponseTemplates(response400Templates);
        client.putIntegrationResponse(putIntegration400ResponseRequest);
    }
    return method;
}