Ejemplo n.º 1
0
 def connect_api_gateway_to_kinesis(self, gateway_name, kinesis_stream):
     resources = {}
     template = self.APIGATEWAY_DATA_INBOUND_TEMPLATE % (kinesis_stream)
     resource_path = self.API_PATH_DATA_INBOUND.replace('/', '')
     resources[resource_path] = [{
         'httpMethod': 'POST',
         'authorizationType': 'NONE',
         'integrations': [{
             'type': 'AWS',
             'uri': 'arn:aws:apigateway:%s:kinesis:action/PutRecords' % config.DEFAULT_REGION,
             'requestTemplates': {
                 'application/json': template
             }
         }]
     }, {
         'httpMethod': 'GET',
         'authorizationType': 'NONE',
         'integrations': [{
             'type': 'AWS',
             'uri': 'arn:aws:apigateway:%s:kinesis:action/ListStreams' % config.DEFAULT_REGION,
             'requestTemplates': {
                 'application/json': '{}'
             }
         }]
     }]
     return aws_stack.create_api_gateway(
         name=gateway_name,
         resources=resources,
         stage_name=self.TEST_STAGE_NAME
     )
Ejemplo n.º 2
0
 def connect_api_gateway_to_http(self,
                                 int_type,
                                 gateway_name,
                                 target_url,
                                 methods=[],
                                 path=None):
     if not methods:
         methods = ['GET', 'POST']
     if not path:
         path = '/'
     resources = {}
     resource_path = path.replace('/', '')
     resources[resource_path] = []
     req_templates = {
         'application/json': json.dumps({'foo': 'bar'})
     } if int_type == 'custom' else {}
     for method in methods:
         resources[resource_path].append({
             'httpMethod':
             method,
             'integrations': [{
                 'type': 'HTTP' if int_type == 'custom' else 'HTTP_PROXY',
                 'uri': target_url,
                 'requestTemplates': req_templates,
                 'responseTemplates': {}
             }]
         })
     return aws_stack.create_api_gateway(name=gateway_name,
                                         resources=resources,
                                         stage_name=self.TEST_STAGE_NAME)
Ejemplo n.º 3
0
    def connect_api_gateway_to_http_with_lambda_proxy(self,
                                                      gateway_name,
                                                      target_uri,
                                                      methods=[],
                                                      path=None):

        if not methods:
            methods = ['GET', 'POST', 'DELETE']
        if not path:
            path = '/'
        resources = {}
        resource_path = path.lstrip('/')
        resources[resource_path] = []
        for method in methods:
            resources[resource_path].append({
                'httpMethod':
                method,
                'integrations': [{
                    'type': 'AWS_PROXY',
                    'uri': target_uri
                }]
            })
        return aws_stack.create_api_gateway(name=gateway_name,
                                            resources=resources,
                                            stage_name=self.TEST_STAGE_NAME)
Ejemplo n.º 4
0
def connect_api_gateway_to_sqs(gateway_name,
                               stage_name,
                               queue_arn,
                               path,
                               region_name=None):
    resources = {}
    template = APIGATEWAY_SQS_DATA_INBOUND_TEMPLATE
    resource_path = path.replace('/', '')
    region_name = region_name or aws_stack.get_region()
    queue_name = aws_stack.sqs_queue_name(queue_arn)
    sqs_region = aws_stack.extract_region_from_arn(queue_arn) or region_name
    resources[resource_path] = [{
        'httpMethod':
        'POST',
        'authorizationType':
        'NONE',
        'integrations': [{
            'type':
            'AWS',
            'uri':
            'arn:aws:apigateway:%s:sqs:path/%s/%s' %
            (sqs_region, TEST_AWS_ACCOUNT_ID, queue_name),
            'requestTemplates': {
                'application/json': template
            },
        }]
    }]
    return aws_stack.create_api_gateway(name=gateway_name,
                                        resources=resources,
                                        stage_name=stage_name,
                                        region_name=region_name)
Ejemplo n.º 5
0
def connect_api_gateway_to_http_with_lambda_proxy(gateway_name,
                                                  target_uri,
                                                  stage_name=None,
                                                  methods=[],
                                                  path=None,
                                                  auth_type=None,
                                                  http_method=None):
    if not methods:
        methods = ['GET', 'POST', 'DELETE']
    if not path:
        path = '/'
    stage_name = stage_name or 'test'
    resources = {}
    resource_path = path.lstrip('/')
    resources[resource_path] = []
    for method in methods:
        int_meth = http_method or method
        resources[resource_path].append({
            'httpMethod':
            method,
            'authorizationType':
            auth_type,
            'integrations': [{
                'type': 'AWS_PROXY',
                'uri': target_uri,
                'httpMethod': int_meth
            }]
        })
    return aws_stack.create_api_gateway(name=gateway_name,
                                        resources=resources,
                                        stage_name=stage_name)
Ejemplo n.º 6
0
def connect_api_gateway_to_sqs(gateway_name,
                               stage_name,
                               queue_arn,
                               path,
                               region_name=None):
    resources = {}
    template = APIGATEWAY_SQS_DATA_INBOUND_TEMPLATE
    resource_path = path.replace("/", "")
    region_name = region_name or aws_stack.get_region()
    queue_name = aws_stack.sqs_queue_name(queue_arn)
    sqs_region = aws_stack.extract_region_from_arn(queue_arn) or region_name
    resources[resource_path] = [{
        "httpMethod":
        "POST",
        "authorizationType":
        "NONE",
        "integrations": [{
            "type":
            "AWS",
            "uri":
            "arn:aws:apigateway:%s:sqs:path/%s/%s" %
            (sqs_region, TEST_AWS_ACCOUNT_ID, queue_name),
            "requestTemplates": {
                "application/json": template
            },
        }],
    }]
    return aws_stack.create_api_gateway(
        name=gateway_name,
        resources=resources,
        stage_name=stage_name,
        region_name=region_name,
    )
Ejemplo n.º 7
0
def connect_api_gateway_to_http_with_lambda_proxy(
    gateway_name,
    target_uri,
    stage_name=None,
    methods=[],
    path=None,
    auth_type=None,
    auth_creator_func=None,
    http_method=None,
):
    if not methods:
        methods = ["GET", "POST", "DELETE"]
    if not path:
        path = "/"
    stage_name = stage_name or "test"
    resources = {}
    resource_path = path.lstrip("/")
    resources[resource_path] = []

    for method in methods:
        int_meth = http_method or method
        resources[resource_path].append(
            {
                "httpMethod": method,
                "authorizationType": auth_type,
                "authorizerId": None,
                "integrations": [{"type": "AWS_PROXY", "uri": target_uri, "httpMethod": int_meth}],
            }
        )
    return aws_stack.create_api_gateway(
        name=gateway_name,
        resources=resources,
        stage_name=stage_name,
        auth_creator_func=auth_creator_func,
    )
Ejemplo n.º 8
0
def connect_api_gateway_to_kinesis(gateway_name, kinesis_stream):
    resources = {}
    template = APIGATEWAY_DATA_INBOUND_TEMPLATE % (kinesis_stream)
    resource_path = API_PATH_DATA_INBOUND.replace('/', '')
    resources[resource_path] = [{
        'httpMethod': 'POST',
        'authorizationType': 'NONE',
        'integrations': [{
            'type': 'AWS',
            'uri': 'arn:aws:apigateway:%s:kinesis:action/PutRecords' % DEFAULT_REGION,
            'requestTemplates': {
                'application/json': template
            }
        }]
    }]
    return aws_stack.create_api_gateway(name=gateway_name, resources=resources,
        stage_name=TEST_STAGE_NAME)
Ejemplo n.º 9
0
def connect_api_gateway_to_http(gateway_name, target_url, methods=[], path=None):
    if not methods:
        methods = ['GET', 'POST']
    if not path:
        path = '/'
    resources = {}
    resource_path = path.replace('/', '')
    resources[resource_path] = []
    for method in methods:
        resources[resource_path].append({
            'httpMethod': method,
            'integrations': [{
                'type': 'HTTP',
                'uri': target_url
            }]
        })
    return aws_stack.create_api_gateway(name=gateway_name, resources=resources,
        stage_name=TEST_STAGE_NAME)
Ejemplo n.º 10
0
def connect_api_gateway_to_http_with_lambda_proxy(gateway_name, target_uri, methods=[], path=None):
    if not methods:
        methods = ['GET', 'POST']
    if not path:
        path = '/'
    resources = {}
    resource_path = path.lstrip('/')
    resources[resource_path] = []
    for method in methods:
        resources[resource_path].append({
            'httpMethod': method,
            'integrations': [{
                'type': 'AWS_PROXY',
                'uri': target_uri
            }]
        })
    return aws_stack.create_api_gateway(name=gateway_name, resources=resources,
        stage_name=TEST_STAGE_NAME)
Ejemplo n.º 11
0
def connect_api_gateway_to_http(gateway_name, target_url, methods=[], path=None):
    if not methods:
        methods = ['GET', 'POST']
    if not path:
        path = '/'
    resources = {}
    resource_path = path.replace('/', '')
    resources[resource_path] = []
    for method in methods:
        resources[resource_path].append({
            'httpMethod': method,
            'integrations': [{
                'type': 'HTTP',
                'uri': target_url
            }]
        })
    return aws_stack.create_api_gateway(name=gateway_name, resources=resources,
        stage_name=TEST_STAGE_NAME)
Ejemplo n.º 12
0
def connect_api_gateway_to_kinesis(gateway_name, kinesis_stream):
    resources = {}
    template_data_inbound = APIGATEWAY_DATA_INBOUND_TEMPLATE % (kinesis_stream)
    resource_data_inbound = API_PATH_DATA_INBOUND.replace('/', '')
    resources[resource_data_inbound] = [{
        'httpMethod': 'POST',
        'authorizationType': 'NONE',
        'apiKeyRequired': True,
        'integrations': [{
            'type': 'AWS',
            'uri': 'arn:aws:apigateway:%s:kinesis:action/PutRecords' % DEFAULT_REGION,
            'requestTemplates': {
                'application/json': template_data_inbound
            }
        }],
        'models': {}
    }]
    return aws_stack.create_api_gateway(name=gateway_name, resources=resources,
        stage_name=TEST_STAGE_NAME)
Ejemplo n.º 13
0
def connect_api_gateway_to_http_with_lambda_proxy(gateway_name,
                                                  target_uri,
                                                  methods=[],
                                                  path=None):
    if not methods:
        methods = ['GET', 'POST']
    if not path:
        path = '/'
    resources = {}
    resource_data_inbound = path.replace('/', '')
    resources[resource_data_inbound] = []
    for method in methods:
        resources[resource_data_inbound].append({
            'httpMethod':
            method,
            'integrations': [{
                'type': 'AWS_PROXY',
                'uri': target_uri
            }]
        })
    return aws_stack.create_api_gateway(name=gateway_name,
                                        resources=resources,
                                        stage_name=TEST_STAGE_NAME)
Ejemplo n.º 14
0
 def connect_api_gateway_to_sqs(self, gateway_name):
     resources = {}
     template = self.APIGATEWAY_SQS_DATA_INBOUND_TEMPLATE
     resource_path = self.API_PATH_DATA_INBOUND.replace('/', '')
     resources[resource_path] = [{
         'httpMethod':
         'POST',
         'authorizationType':
         'NONE',
         'integrations': [{
             'type':
             'AWS',
             'uri':
             'arn:aws:apigateway:%s:sqs:path/%s/%s' %
             (DEFAULT_REGION, TEST_AWS_ACCOUNT_ID, self.TEST_SQS_QUEUE),
             'requestTemplates': {
                 'application/json': template
             },
         }]
     }]
     return aws_stack.create_api_gateway(name=gateway_name,
                                         resources=resources,
                                         stage_name=self.TEST_STAGE_NAME)