Hello everyone, i have been integrating pulumi for...
# general
d
Hello everyone, i have been integrating pulumi for integrating with api gateway but I ran into some issue.
Copy code
ids:list[pulumi.output.Output] =[] #contains ids of the resources to be deployed
deployment = apigateway.Deployment("test_deployment",
        rest_api=restapi.id,
        triggers={
            "redeployment":pulumi.Output.all(ids)
            .apply(lambda exampleResourceId: json.dumps([exampleResourceId]))
            .apply(lambda to_json: hashlib.sha1(to_json.encode()).hexdigest()),      
        }
    )
as pulumi.Output.all function accepts the pulumi.output.Output not list[pulumi.output.Output], I am getting error. How should I pass the above ids into pulumi.Output.all function so that all the ids in the list can passed? (a list can contain any number of elements)
e
all
is an
*args
method, so if you’ve already got a list you want to “splat” it like
Output.all(*ids)
d
I have tried this too. getting below error
Copy code
transformed: Input[U] = func(value)
      File "/home/sanskar_gupta/api_gateway_poc/./process.py", line 78, in <lambda>
        .apply(lambda exampleResourceId: json.dumps([exampleResourceId]))
      File "/usr/lib/python3.8/json/_init_.py", line 231, in dumps
        return _default_encoder.encode(obj)
      File "/usr/lib/python3.8/json/encoder.py", line 199, in encode
        chunks = self.iterencode(o, _one_shot=True)
      File "/usr/lib/python3.8/json/encoder.py", line 257, in iterencode
        return _iterencode(o, 0)
      File "/usr/lib/python3.8/json/encoder.py", line 179, in default
        raise TypeError(f'Object of type {o._class_._name_} '
    TypeError: Object of type Method is not JSON serializable
e
Hard to say without all the code context. Looks like something isn’t quite lined up with your “ids” variable. How is it being set, and did you change the “all” call to use *?
d
I am attaching a complete snippet of code for better understanding. I hope this works
Copy code
from pulumi_aws import apigateway


def create_resource(name:str, restapi_id:str, parent_id:str, path_part:str):
    resource = apigateway.Resource(name,
        rest_api=restapi_id,
        parent_id=parent_id,
        path_part=path_part   
    )    
    return resource


def create_method(name:str, rest_api_id:str, resource_id:str,  method_params:str,method_type:str):
    method = apigateway.Method(name,
        rest_api=rest_api_id,
        resource_id=resource_id,
        http_method=method_type,
        request_parameters=method_params,
        authorization="NONE",
    )
    return method


def deploy(restapi, ids:list):
    deployment = apigateway.Deployment(DeploymentConstants.NAME,
        rest_api=restapi.id,
        triggers={
            "redeployment":pulumi.Output.all(*ids)
            .apply(lambda exampleResourceId: json.dumps([exampleResourceId]))
            .apply(lambda to_json: hashlib.sha1(to_json.encode()).hexdigest()),      
        }
    )



def main():
    ids = []
    for i in range(10):
        name = str(i)+"_resource"
        res = create_resource(name, restapi.id, other_resource.id, "path_part_"+name)
        meth_name = str(i)+"_method"
        method_response = create_method(name, restapi.id, other_resource.id, None, "GET")
        ids.append(res.id)
        ids.append(method_response.id)
    deploy(restapi, ids)


if __name__=="__main__":
    main()
e
Can’t see anything obviously wrong with that, I can test it out later check there aren’t any bugs due to the SDK
d
Sure @echoing-dinner-19531. Let me know once you find the issue.
Hi @echoing-dinner-19531, is there any method so that I can track the status of this issue or any time limit till when this can be resolved? My work is pending because of this.
e
I can give this a try now actually, should be quick to see whats up once its actually running
d
alright. Thanks
e
hmm I'm not seeing any issue with the Output.all(*id) and json.dumps
Happy to help but you will need to send over the code that actual reproduces that error, it's probably some tiny issue and trying to guess that from example code isn't going to be possible.
d
sure @echoing-dinner-19531. Can you share the preferred channel so that I can share the code with you as posting it here publicly wouldn't be a good idea.
e
You can email it to me at fraser@pulumi.com
d
Hi @echoing-dinner-19531, it seems I have figured out and solved the issue. very thanks for your coordination and time. Happy to use Pulumi. 🙂
🙌 1