dry-dentist-95091
10/03/2022, 8:32 AMids: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)echoing-dinner-19531
10/03/2022, 9:42 AMall
is an *args
method, so if you’ve already got a list you want to “splat” it like Output.all(*ids)
dry-dentist-95091
10/03/2022, 9:49 AMtransformed: 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
echoing-dinner-19531
10/03/2022, 11:36 AMdry-dentist-95091
10/03/2022, 12:16 PMfrom 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()
echoing-dinner-19531
10/03/2022, 1:29 PMdry-dentist-95091
10/04/2022, 4:52 AMechoing-dinner-19531
10/04/2022, 8:26 AMdry-dentist-95091
10/04/2022, 8:30 AMechoing-dinner-19531
10/04/2022, 8:37 AMdry-dentist-95091
10/04/2022, 9:05 AMechoing-dinner-19531
10/04/2022, 9:06 AMdry-dentist-95091
10/04/2022, 9:18 AM