alert-raincoat-8148501/29/2021, 1:59 AM
where i am running load balancer creating api and running boto call to get an ARN of that load balancer as
raise error_class(parsed_response, operation_name) botocore.errorfactory.LoadBalancerNotFoundException: An error occurred (LoadBalancerNotFound) when calling the DescribeLoadBalancers operation: Load balancers '[test-lb]' not found error: an unhandled error occurred: Program exited with non-zero exit code: 1
Is there any way to handle this situation in pulumi or exception?
load_balancer = aws.lb.LoadBalancer( # type: ignore "Test-LoadBalancer", name=stacktname + "-lb", load_balancer_type="network", internal="true", subnets=subnets, enable_deletion_protection=True, ) nlb_name = stackname + "-lb" try: client = boto3.client("elbv2") except botocore.exceptions.ClientError as error: raise error nlb_response = client.describe_load_balancers(Names=[nlb_name]) loadbal_arn = nlb_response["LoadBalancers"]["LoadBalancerArn"]
billowy-army-6859901/29/2021, 2:23 AM
but you're setting the name of the created loadbalancer to
stacktname + "-lb"
alert-raincoat-8148501/29/2021, 2:26 AM
billowy-army-6859901/29/2021, 2:46 AM
. Output's are like a python coroutine, you need to wait until they're finished before you do the describe
alert-raincoat-8148501/29/2021, 2:56 AM
. Output’s are like a python coroutine, you need to wait until they’re finished before you do the describe” And this is what i am looking for, if i can apply something like async or wait function in it.
billowy-army-6859901/29/2021, 3:01 AM
alert-raincoat-8148501/29/2021, 3:07 AM
output is coming in form of
but not actual a string.
<pulumi.output.Output object at 0x1075c4430>
billowy-army-6859901/29/2021, 3:23 AM
, so as I said before, you need to do that in an apply. You don't need to use boto3 at all. give me a few minutes
alert-raincoat-8148501/29/2021, 3:24 AM
billowy-army-6859901/29/2021, 3:28 AM
def write_to_file(arn): f = open("arn.txt", "a") f.write(arn) f.close() # anything that is run inside an apply runs only when the resource has finished # creating and has returned the value you're applying, in this case, the arn json = lb.arn.apply(lambda a: write_to_file(arn=a))
only after the actual resource has been created and the API has returned a value to you. That's what apply does
alert-raincoat-8148501/29/2021, 3:35 AM
quiet-leather-9475501/30/2021, 8:02 AM
, you have to pass your action as a lambda that Pulumi can run once the resource referenced by the Output has been deployed / updated.