That `Object of type 'Output' is not JSON serializ...
# general
f
That
Object of type 'Output' is not JSON serializable
suggests to me you need an 'apply' somewhere https://www.pulumi.com/docs/intro/concepts/programming-model/#outputs
f
Is
apply
generally called in the source stack before outputting a value or in the downstream stack? fwiw, changing the get_output to
image = image_stack.get_output("image").apply(lambda x: str(x))
resulted in the same error
f
It's a lazy evaluation where you need it, hence the lambda, so downstream?
I hit something similar when trying to incluede e.g. S3 arns in RolePolicy (e.g. needed to use bucket.arn.apply() inside the RolePolicy document)
This was all inside one stack though, so not sure about cross-stack
f
I tried
"image": image.apply(lambda x: str(x)),
too, no luck
i bring up the runtime bc I have a bunch of other get_output calls from another python stack that work fine e.g.
cluster_arn = infra_stack.get_output("cluster_arn")
Also, ā€¢
image.apply(lambda x: print(x))
prints the string value correctly ā€¢
pulumi.Output.concat("", image)
and
image.apply(lambda x: x)
give the error
f
I can only suggest you dig through https://github.com/pulumi/examples and see if you can find a working example
f
šŸ‘ thanks
f
(I just started using Pulumi on the weekend :))
šŸ’Æ 1
Keen on sharing more python examples though šŸ™‚
f
I figured it out, it's because of the
json.dumps
. It needs to be:
Copy code
container_definitions = image.apply(
            lambda image: json.dumps(
                [
                    {
                        "name": "my-app",
                        "image": image,
                        "portMappings": [{"containerPort": port, "protocol": "tcp"}],
                    }
                ]
            )
        )

        task_definition = ecs.TaskDefinition(
            name,
            family=name,
            cpu="256",
            memory="512",
            network_mode="awsvpc",
            requires_compatibilities=["FARGATE"],
            execution_role_arn=role.arn,
            container_definitions=container_definitions,
            opts=child_opts,
        )