https://pulumi.com logo
#general
Title
# general
f

fancy-ice-8211

04/27/2020, 10:41 PM
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

fast-activity-86095

04/27/2020, 10:44 PM
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

fancy-ice-8211

04/27/2020, 10:45 PM
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

fast-activity-86095

04/27/2020, 10:49 PM
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

fancy-ice-8211

04/27/2020, 11:02 PM
I can only suggest you dig through https://github.com/pulumi/examples and see if you can find a working example
f

fast-activity-86095

04/27/2020, 11:03 PM
šŸ‘ thanks
f

fancy-ice-8211

04/27/2020, 11:03 PM
(I just started using Pulumi on the weekend :))
šŸ’Æ 1
Keen on sharing more python examples though šŸ™‚
f

fast-activity-86095

04/27/2020, 11:31 PM
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,
        )
12 Views