Skip to content

"aws configure set" breaks the credentials file because it doesn't add new-line when creating a new profile #6874

@LazaroOnline

Description

@LazaroOnline

Describe the bug

The aws-cli command:
aws configure set ... -profile SomeNewProfileNameHere
creates a new profile if the specified profile "SomeNewProfileNameHere" doesn't exist.
The problem is that if the file ends without a new-line, the command will append the new profile right after the last character in the file breaking the credentials configuration file.

Expected Behavior

The aws configure set command should add a new line if required so that it doesn't break the config file.

Current Behavior

The aws configure set command is appending blindly the new profile at the end of the file without adding a new line.

Reproduction Steps

Start with a config file like this: \.aws\credentials:

[default]
region=eu-west-1
[OtherProfile]
region=eu-west-1

after running:
aws configure set aws_secret_access_key 12345 --profile SomeNewProfileNameHere

[default]
region=eu-west-1
[OtherProfile]
region=eu-west-1[SomeNewProfileNameHere]
aws_secret_access_key = 12345

Which is invalid!
It should be:

[default]
region=eu-west-1
[OtherProfile]
region=eu-west-1

[SomeNewProfileNameHere]
aws_secret_access_key = 12345

Possible Solution

Add a new line always when adding a new profile to the credentials file.

Additional Information/Context

No response

CLI version used

aws-cli/2.4.25 Python/3.8.8 Windows/10 exe/AMD64 prompt/off

Environment details (OS name and version, etc.)

Windows/10 updated 2022-04-12

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions