def _create_custom_resource()

in apigw-vpce-helpers/apigw_vpce_helpers/vpce_helpers.py [0:0]


def _create_custom_resource(stack, name: str, **kwargs) -> core.CustomResource:
    parent_dir = pathlib.Path(__file__).parent
    code_dir = str(parent_dir.joinpath('custom_resource'))
    code = lambda_.Code.from_asset(code_dir)

    custom_resource_func = lambda_.SingletonFunction(
        stack,
        f"{name}-CustomResourceFunction",
        uuid='f150930b-586f-4d65-b701-d44cb44057e6',
        code=code,
        handler="handler.main_handler",
        timeout=core.Duration.seconds(15),
        runtime=lambda_.Runtime.PYTHON_3_8,
    )
    custom_resource_func.add_to_role_policy(
        iam.PolicyStatement(
            actions=["ec2:DescribeNetworkInterfaces"],
            effect=iam.Effect.ALLOW,
            resources=['*'],
        )
    )

    return core.CustomResource(
        stack,
        f"{name}-ENIPrivateIPResource",
        service_token=custom_resource_func.function_arn,
        properties=kwargs,
    )