Commit 6cffca0
authored
fix(cli): ecs hotswap fails on log configuration enabled (aws#26876)
## Problem
ECS hotswap fails on a task definition containing log configuration like the following.
```ts
const taskDefinition = new ecs.FargateTaskDefinition(stack, 'Task', {});
taskDefinition.addContainer('EcsApp', {
image: ecs.ContainerImage.fromRegistry('nginx:stable'),
logging: ecs.LogDriver.awsLogs({ streamPrefix: 'log' }),
});
```
## Root cause
When we transform object keys in a task definition, we pass `excludeFromTransform` to avoid from transforming keys with arbitrary string, such as [`logDriver.options`](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html#ECS-Type-LogConfiguration-options).
However, it was not working when we transform keys with upperCaseFirstCharacter, because the keys in `excludeFromTransform` was uppercased, where the source object was lowercased.
```
// source task definition
{
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "my-test-stack-TaskEcsAppLogGroupD5C9C1DD-BPB6zgX4S0wU",
"awslogs-region": "ap-northeast-1",
},
},
}
// excludeFromTransform
{
LogConfiguration: {
Options: true,
},
},
}
// where it should be
{
logConfiguration: {
options: true,
},
},
}
```
This misconfiguration resulted in the output task definition uppercased in an unexpected way:
```json
{
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"Awslogs-group": "my-test-stack-TaskEcsAppLogGroupD5C9C1DD-BPB6zgX4S0wU",
"Awslogs-region": "ap-northeast-1",
},
},
}
```
The problem was not detected by unit tests because they only contained cases with uppercase keys in a source task definition.
## Fix
Use lowercased `excludeFromTransform` when we use it with `upperCaseFirstCharacter`, also adding a test case with lowercased keys in a source task definition.
Closes aws#26871.
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*1 parent 702d9d5 commit 6cffca0
2 files changed
Lines changed: 15 additions & 5 deletions
File tree
- packages/aws-cdk
- lib/api/hotswap
- test/api/hotswap
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| 135 | + | |
135 | 136 | | |
136 | | - | |
| 137 | + | |
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
| |||
Lines changed: 13 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
812 | 812 | | |
813 | 813 | | |
814 | 814 | | |
815 | | - | |
| 815 | + | |
816 | 816 | | |
817 | 817 | | |
818 | 818 | | |
819 | 819 | | |
820 | 820 | | |
821 | | - | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
822 | 831 | | |
823 | 832 | | |
824 | 833 | | |
| |||
846 | 855 | | |
847 | 856 | | |
848 | 857 | | |
849 | | - | |
| 858 | + | |
850 | 859 | | |
851 | 860 | | |
852 | 861 | | |
| |||
887 | 896 | | |
888 | 897 | | |
889 | 898 | | |
890 | | - | |
| 899 | + | |
891 | 900 | | |
892 | 901 | | |
893 | 902 | | |
| |||
0 commit comments