Skip to content

Asynchronous call inside a Policy Pack

Open

Description

What happened?

When I'm trying to call an asynchronous API inside a policy pack, it generates this error:
"error: Exception calling application: There is no current event loop in thread 'ThreadPoolExecutor-0_0'. ".
Even if I add async/await to the function or even using pulumi.routine.sync_await the asyncronous call doesn't work.
I think is missing the asyncio.get_event_loop() function in the generation of the thread when is called the policy Pack.

This is the function:

def validator(args: ResourceValidationArgs, report_violation: ReportViolation):
    if args.resource_type != "aws:s3/bucket:Bucket":
        return
    
    resource =_sync_await(aws.pricing.get_product(
    service_code="AmazonS3",
    filters= [
        aws.pricing.GetProductFilterArgs(field = "productFamily", value = "Storage"),
    ]))
    if resource is None:
        report_violation("The resource has not been found")
    else:
        print(resource)
    if resource["price"] > 0:
        report_violation("The resource has a cost")
    else:
        report_violation("The resourse is free")

Expected Behavior

I would expect that at least the function generates an output but it doesn't.

Steps to reproduce

Create a policy pack.
Add the function written in the description.
Create a ResourceValidationPolicy and a PolicyPack
Try to execute it with a project.

Output of pulumi about

error: Exception calling application: There is no current event loop in thread 'ThreadPoolExecutor-0_0'

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    impact/usabilitySomething that impacts users' ability to use the product easily and intuitivelySomething that impacts users' ability to use the product easily and intuitivelykind/bugSome behavior is incorrect or out of specSome behavior is incorrect or out of spec

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions