Ejemplo n.º 1
0
    def add_path(path, parts, parent_id=""):
        child_id = create_resource_id()
        path = path or "/"
        child = apigateway_models.Resource(
            id=child_id,
            region_name=rest_api.region_name,
            api_id=rest_api.id,
            path_part=parts[-1] or "/",
            parent_id=parent_id,
        )
        for m, payload in body["paths"].get(path, {}).items():
            m = m.upper()
            payload = payload["x-amazon-apigateway-integration"]

            child.add_method(m, None, None)
            integration = apigateway_models.Integration(
                http_method=m,
                uri=payload.get("uri"),
                integration_type=payload["type"],
                pass_through_behavior=payload.get("passthroughBehavior"),
                request_templates=payload.get("requestTemplates") or {},
            )
            integration.create_integration_response(
                status_code=payload.get("responses", {}).get("default", {}).get("statusCode", 200),
                selection_pattern=None,
                response_templates=None,
                content_handling=None,
            )
            child.resource_methods[m]["methodIntegration"] = integration

        rest_api.resources[child_id] = child
        return child
 def Resource_create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
     props = cloudformation_json['Properties']
     region_name = props.get('Region') or aws_stack.get_region()
     path_part = props.get('PathPart')
     api_id = props.get('RestApiId')
     parent_id = props.get('ParentId')
     id = props.get('Id') or short_uid()
     return apigw_models.Resource(id, region_name, api_id, path_part, parent_id)