Running into an issue with an ECS task definition ...
# dotnet
n
Running into an issue with an ECS task definition
Copy code
* 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
Copy code
{"environment", new[] { new Dictionary<string, object> {
                                    {"PG_ENDPOINT", "potato"},
                                    {"PG_READ_ENDPOINT", "banana"},
                                    {"ASPNETCORE_URLS", "test"}
                                }}
                            },
Improperly.
b
Are you sure that
environment
key is expecting an array of dictionaries instead of just a dictionary?
n
Copy code
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
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
I run 3 duplicate region stacks with different task definitions on each.
Copy code
[{"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
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
ah fun, lemme whip that up real fast.
n
Copy code
"environment":[{"Key":"PG_ENDPOINT","Value":"potato"},{"Key":"PG_READ_ENDPOINT","Value":"banana"},{"Key":"ASPNETCORE_URLS","Value":"test"}]
closer
b
that worked instead of
name
? weird
n
Didn't work, but it's atleast formatted correctly.
b
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
Copy code
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