Im having trouble passing two Output callback values into a container definition. I am doing this:
redis_url = redis.cache_nodes.apply(lambda cache_nodes: cache_nodes[0].get('address'))
task_definition = aws.ecs.TaskDefinition('task',
family='task-definition',
cpu='256',
memory='512',
network_mode='awsvpc',
requires_compatibilities=['FARGATE'],
execution_role_arn=role.arn,
container_definitions=cloudwatchgroup.name.apply(generate_container_definition)
)
def generate_container_definition(log_group_name):
return json.dumps([{
'name': 'api',
'image': 'api/api:latest',
'portMappings': [{
'containerPort': 80,
'hostPort': 80,
'protocol': 'tcp'
}],
'logConfiguration': {
'logDriver': 'awslogs',
'options': {
'awslogs-group': log_group_name,
'awslogs-region': aws.get_region().name,
}
},
'environment' : [
{ 'name' : 'ENV', 'value' : config.get('ENV') },
{ 'name' : 'REDIS_URL', 'value' : redis_url }
]
}])
but then Im getting: TypeError: Object of type Output is not JSON serializable
Is there a way to pass two output values into that function definition or am I doing something wrong?
You can use Output.all
to combine multiple outputs. Something like
def generate_container_definition(log_group_name, redis_url):
...
container_definitions = Output.all(cloudwatchgroup.name, redis.cache_nodes)
.apply(lambda args: generate_container_definition(args[0], args[1][0].get('address')))