Beispiel #1
0
 def _endpoint(self, rest_api, path_part):
     _name = f"{self.name}-{path_part}"
     endpoint = apigateway.Resource(
         _name,
         opts=pulumi.ResourceOptions(depends_on=[rest_api]),
         parent_id=rest_api.root_resource_id,
         path_part=path_part,
         rest_api=rest_api.id,
     )
     method = apigateway.Method(
         _name,
         opts=pulumi.ResourceOptions(depends_on=[rest_api, endpoint]),
         http_method="GET",
         rest_api=rest_api.id,
         resource_id=endpoint.id,
         authorization="NONE",
     )
     integration = apigateway.Integration(
         _name,
         opts=pulumi.ResourceOptions(
             depends_on=[rest_api, endpoint, method]),
         integration_http_method="POST",
         http_method=method.http_method,
         type="AWS",
         uri=self._lambda.invoke_arn,
         resource_id=endpoint.id,
         rest_api=rest_api.id,
     )
     method_response = apigateway.MethodResponse(
         _name,
         opts=pulumi.ResourceOptions(
             depends_on=[rest_api, endpoint, method]),
         http_method=method.http_method,
         rest_api=rest_api.id,
         resource_id=endpoint.id,
         status_code=200,
     )
     integration_response = apigateway.IntegrationResponse(
         _name,
         opts=pulumi.ResourceOptions(
             depends_on=[rest_api, endpoint, method, integration]),
         http_method=method.http_method,
         rest_api=rest_api.id,
         resource_id=endpoint.id,
         status_code=200,
     )
     responses = [method_response, integration_response]
     return endpoint, [method, integration] + responses
Beispiel #2
0
    role=iam.lambda_role.arn,
)

example_api = apigateway.RestApi(
    'ServerlessExample', description='Pulumi Lambda API Gateway Example')

proxy_root_met = apigateway.Method('proxy_root',
                                   rest_api=example_api,
                                   resource_id=example_api.root_resource_id,
                                   http_method='ANY',
                                   authorization='NONE')

example_root_int = apigateway.Integration(
    'lambda_root',
    rest_api=example_api,
    resource_id=proxy_root_met.resource_id,
    http_method=proxy_root_met.http_method,
    integration_http_method='POST',
    type='AWS_PROXY',
    uri=example_fn.invoke_arn)

example_dep = apigateway.Deployment(
    'example',
    rest_api=example_api,
    stage_name="example-test",
    __opts__=ResourceOptions(depends_on=[example_root_int]))

example_perm = lambda_.Permission(
    "apigw",
    statement_id="AllowAPIGatewayInvoke",
    action="lambda:InvokeFunction",
    function=example_fn,
Beispiel #3
0
    method = apigateway.Method(
        f"exampleMethod{i}",
        http_method="ANY",
        resource_id=resource_id,
        api_key_required=False,
        request_parameters={},
        authorization="NONE",
        rest_api=gateway.id,
    )

    integration = apigateway.Integration(
        f"exampleIntegration{i}",
        rest_api=gateway.id,
        resource_id=resource_id,
        http_method=method.http_method,
        integration_http_method="POST",
        type="AWS_PROXY",
        uri=example_function.arn.apply(
            lambda arn:
            f"arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/{arn}/invocations"
        ),
    )

    methods.append(method)
    integrations.append(integration)

deployment = apigateway.Deployment(
    "exampleDeployment",
    rest_api=gateway.id,
    opts=ResourceOptions(depends_on=[*methods, *integrations]),
)