# cat /dev/head

a developers log

About multiple slashes (/) in AWS S3 key path

Here is a short note about accessing files stored in AWS S3 bucket.

On Linux (and probably all UNIX as well) systems, if you will try to access some path on command line, any adjacent slashes will be ignored (or interpreted as single one). Thus it's possible to do something like this:

ls /path/to///a///file.txt

And this will work fine. Although you don't do it normally, when you type path by hand, it is quite possible to happen in shell scripts, where full path is concatenated from variables. I usually put a trailing / at end of path that is assigned to a variable, but also separate path variables and constants with a / as well - just for sake of it, to not end up with a messed up path.

printf "%s/%s/file.txt\n" "$HOME" "$SOME_PATH"

Situation is different for AWS S3. I'm used to Linux shell behaviour, and in a user data script that is run on EC2 instance I fetch some files from S3. Full path to the files is a concatenation of some variables. However this command aws s3 cp s3://example-com/path/to/a/file.txt . is not the same as aws s3 cp s3://example-com/path/to//a/file.txt .. For the first case, aws cli will do what it is expected to - copy file from S3 to local drive. Second one unfortunately will do exactly nothing - not even raise an error.

Keep that in mind while working with aws cli and S3 in your scripts.

aws S3, tips