The Amazon ECS CLI enables users to run their applications on ECS/Fargate using the Docker Compose file format, quickly provision resources, push/pull images in ECR, and monitor running applications on ECS/Fargate.
The resulting user-data script from cluster up has an erroneous newline which results in an invalid user-data script being sent to the EC2 instance. Older versions of Cloud-init ignored the issue (19-?, seen in AL2), but newer versions (22.2.2, seen in AL2023) correctly parse shell-scripts, causing the provided script to fail.
Summary
The resulting user-data script from cluster up has an erroneous newline which results in an invalid user-data script being sent to the EC2 instance. Older versions of Cloud-init ignored the issue (19-?, seen in AL2), but newer versions (22.2.2, seen in AL2023) correctly parse shell-scripts, causing the provided script to fail.
Description
Bug is here: https://github.com/aws/amazon-ecs-cli/blob/2791f9b45c3a2cf2788278a0d9eb529650ade8f1/ecs-cli/modules/cli/cluster/userdata/user_data.go#L153-L156
Golang's MIME multipart writer already inserts a newline, leaving the resulting script with an erroneous newline at the start of the file: https://github.com/golang/go/blob/master/src/mime/multipart/writer.go#L120
Expected Behavior
/var/lib/cloud/instance/scripts/part-001:
Observed Behavior
/var/lib/cloud/instance/scripts/part-001: