Hi!!! A newbie over here!! I have an issue with ou...
# getting-started
g
Hi!!! A newbie over here!! I have an issue with outputs in python. I have all my env vars in a common stack so from any service I can query my common vars which is nice. I want to use those variables in a ECS task but... To define them I have to "unwrap" all my outputs (envars) chaining
apply
calls any idea how to solve this? My goal is to have a key/value array of strings with all my vars
b
you're trying to get outputs into the ecs task string right?
g
Yep!!! The json_dunp that explodes when you try to serialise an Output 😅 🤣
b
what have you tried?
g
I think that I can solve the problem in that way
The only issue that I see is that I don't have the
enviroment
property like in the example with a fixed structure I have a variable array I need to find a way to unwrap all the outputs inside that array but I guess that I can use another Output.all to construct that array
Let me try!
Thanks!!!!
hey!! your suggestion worked like a charm! now each service picks the neccesary outputs from the common stack an prepare the
env_var
array in this way:
Copy code
env_vars = Output.all(env_var1, env_var2).apply(
  lambda args: [
      {
        'name': 'TEST_VAR1',
        'value':args[0]
      },
      {
        'name': 'TEST_VAR2',
        'value':args[1]
      }
    ]
)
and this output is passed to the client that generates the ECS task where the env vars are injected in this way:
Copy code
return Output.all(image=image.image_name, envVars=envVars).apply(
      lambda args: json.dumps([{
        'name': name,
        'image': args['image'],
        'portMappings': [{
          'containerPort': 8080,
          'hostPort': 8080,
          'protocol': 'tcp'
        }],
        'environment': args['envVars']
      }])
    )
Again Thanks for your help!!
b
my pleasure!