https://pulumi.com logo
Title
n

nice-scientist-89715

07/06/2021, 4:19 PM
Running into an issue with an ECS task definition
* ClientException: Environment variable name cannot be null or blank.
Seems to stem from the ContainerDefinitions https://gist.github.com/urothis/197e866016a47d7f9db8e03596d2ef5b Probably related to doing
{"environment", new[] { new Dictionary<string, object> {
                                    {"PG_ENDPOINT", "potato"},
                                    {"PG_READ_ENDPOINT", "banana"},
                                    {"ASPNETCORE_URLS", "test"}
                                }}
                            },
Improperly.
b

bored-oyster-3147

07/06/2021, 4:21 PM
Are you sure that
environment
key is expecting an array of dictionaries instead of just a dictionary?
n

nice-scientist-89715

07/06/2021, 4:22 PM
aws:ecs:TaskDefinition (api-runner-us-development):
    error: aws:ecs/taskDefinition:TaskDefinition resource 'api-runner-us-development' has a problem: ECS Task Definition container_definitions is invalid: Error decoding JSON: json: cannot unmarshal object into Go struct field ContainerDefinition.Environment of type []*ecs.KeyValuePair. Examine values at 'TaskDefinition.ContainerDefinitions'.
When I try to remove the new[]
b

bored-oyster-3147

07/06/2021, 4:25 PM
My container definition is an object on the
environment
key and not an array. I would examine the JSON that is being returned from
JsonSerializer.Serialize
when you omit the
new []
and verify that it is valid
I find that it is much easier in my infrastructure code to keep my container definition in a separate
.json
file and load it (doing any necessary variable placement) when I need the JSON. Your gist is just a bunch of static fields without any variable replacement into your container definition so there really isn't any reason to have the added complexity of creating strongly typed objects to represent it and then serialize when you could just load an already-valid JSON file
n

nice-scientist-89715

07/06/2021, 4:31 PM
I run 3 duplicate region stacks with different task definitions on each.
[{"name":"first","image":"***.<http://dkr.ecr.us-west-2.amazonaws.com/***:***%22,%22environment%22:[{%22PG_ENDPOINT%22:%22potato%22,%22PG_READ_ENDPOINT%22:%22banana%22,%22ASPNETCORE_URLS%22:%22test%22}],%22cpu%22:10,%22memory%22:512,%22essential%22:true,%22portMappings%22:[{%22containerPort%22:5000,%22hostPort%22:80}]|dkr.ecr.us-west-2.amazonaws.com/***:***","environment":[{"PG_ENDPOINT":"potato","PG_READ_ENDPOINT":"banana","ASPNETCORE_URLS":"test"}],"cpu":10,"memory":512,"essential":true,"portMappings":[{"containerPort":5000,"hostPort":80}]>}]
How does that compare with yours?
b

bored-oyster-3147

07/06/2021, 4:36 PM
oh here is the issue with your environment shape, it is expecting this:
"environment": [{"name": "variable-name", "value": "variable-value" }]
It is expecting an array of objects that each have the properties
name, value
so it is not expecting a dictionary
n

nice-scientist-89715

07/06/2021, 4:38 PM
ah fun, lemme whip that up real fast.
n

nice-scientist-89715

07/06/2021, 4:46 PM
"environment":[{"Key":"PG_ENDPOINT","Value":"potato"},{"Key":"PG_READ_ENDPOINT","Value":"banana"},{"Key":"ASPNETCORE_URLS","Value":"test"}]
closer
b

bored-oyster-3147

07/06/2021, 4:49 PM
that worked instead of
name
? weird
n

nice-scientist-89715

07/06/2021, 4:50 PM
Didn't work, but it's atleast formatted correctly.
b

bored-oyster-3147

07/06/2021, 4:53 PM
My container def files tend to look like this. And then in my pulumi code I will load this file and just do a string replace of the `{variable}`s
n

nice-scientist-89715

07/06/2021, 5:00 PM
namespace IAC.Helpers {
    public class DockerVarHelper {
        public string name { get; }
        public string value { get; }
        public DockerVarHelper(string Name, string Value) {
            name = Name;
            value = Value;
        }
    }
}
Ended up making this and it works as expected.
Much appreciated for the assistance.
🙌 1