Example usage for com.amazonaws.services.apigateway.model CreateResourceRequest setParentId

List of usage examples for com.amazonaws.services.apigateway.model CreateResourceRequest setParentId

Introduction

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

Prototype


public void setParentId(String parentId) 

Source Link

Document

[Required] The parent resource's identifier.

Usage

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

License:Apache License

CreateResourceResult createTopLevelResourceOnApi(String resourceName, String restApiId, AmazonApiGateway client,
        LambdaLogger logger) {/*from   w ww  .  java  2 s.  c  o  m*/
    logger.log("Creating top-level resource: " + resourceName);
    // Short sleep - this avoids the Too Many Requests error in this
    // custom resource when creating the cloudformation stack.
    pause(logger);
    CreateResourceRequest createResourceRequest = new CreateResourceRequest();
    createResourceRequest.setRestApiId(restApiId);
    if (resourceName.equals("bookings")) {
        createResourceRequest.setPathPart("bookings");
    } else if (resourceName.equals("bookingrules")) {
        createResourceRequest.setPathPart("bookingrules");
    } else if (resourceName.equals("validdates")) {
        createResourceRequest.setPathPart("validdates");
    } else if (resourceName.equals("reservationform")) {
        createResourceRequest.setPathPart("reservationform");
    } else if (resourceName.equals("cancellationform")) {
        createResourceRequest.setPathPart("cancellationform");
    } else {
        throw new InvalidParameterException("Invalid resource name: " + resourceName);
    }

    // Get the id of the parent resource
    GetResourcesRequest getResourcesRequest = new GetResourcesRequest();
    // High enough limit for now
    getResourcesRequest.setLimit(10);
    getResourcesRequest.setRestApiId(restApiId);
    GetResourcesResult resourcesResult = client.getResources(getResourcesRequest);
    String rootResourceId = resourcesResult.getItems().stream()
            .filter(resource -> resource.getPath().equals("/")).findFirst().get().getId();
    logger.log("Parent(root) resource id: " + rootResourceId);
    createResourceRequest.setParentId(rootResourceId);

    return client.createResource(createResourceRequest);
}