Introduction
Most of the tasks in aws can be operated with aws commands. The only command I couldn’t find in the official documentation was “create folder,” which should be on the screen.
The concept of a folder in S3
In fact, the concept of folders does not exist in S3. https://docs.aws.amazon.com/ja_jp/AmazonS3/latest/dev/UsingMetadata.html
The data model of Amazon S3 is a flat structure. Buckets are created and objects are stored in those buckets. There is no hierarchy of sub-buckets or sub-folders. However, a logical hierarchy can be implied by using key name prefixes and delimiters, such as those used in the Amazon S3 console.
So, for one bucket, there are no folders in it, and it is an image of a large number of files.
So what do we do?
I don’t have a directory, but I’ll just dump it in directly!
aws s3 cp sample.txt s3://test/sample-folder/
This will create a sample-folder in the test bucket. Copy the sample.txt file into it. Reference: Breaking the illusion of “folder” in Amazon S3 and revealing its reality https://dev.classmethod.jp/cloud/aws/amazon-s3-folders/
If multiple environments are registered in the .aws directory, it is possible to specify the profile to be loaded with -profile role-a-profile.
If you want to copy the whole directory, use
--recursive
option to copy the entire directory recursively.