In this hands-on exercise, you will use the AWS CLI to access Amazon Simple Storage Service to access S3.
By the end of this hands-on exercise, you should be able to do the following:
In this task, you will create an S3 bucket using one of the commands in CLI which is the mb command (mb = make bucket).
1. Open your terminal (for macOS/Linux OS) or Windows PowerShell (for Windows).
2. Access your AWS resources through AWS CLI. Need a refresher? Have a little peek at Task 3 in our previous exercise about installing AWS CLI.
3. Once you successfully complete step 2 in this task, let's create a bucket.
Type the following command:
The following mb command creates a bucket. In this example, the user makes the bucket mybucket. Replace RANDOM_NUMBER with a random number so that it would make your bucket unique. By default, if you do not specify a Region in the command, the Region will be the same as the one you used when entering your access key ID and secret access key in step 2.
BONUS: If you're curious, here's how you would specify a region (us-west-1):
4. Once you finish the mb command, the expected output would be:
In this task, you will upload a file from your local computer to the S3 bucket that you've created.
1. Choose any file from your local computer, e.g. an image or text file.
To upload the file from your local computer, the command would look like this: aws s3 cp "<location_of_file>" s3://<bucket_name>
For example:
*Don't know how to find your file's file path?
2. You should see an output similar to the below one after you successfully run the command.
3. To verify if the uploaded file is in the S3 bucket, type the command:
4. The output would look similar to this:
In this task, you will delete the S3 object and the S3 bucket. You will use the following commands:
1. To delete the S3 object, type the command:
2. You should see an output like this:
3. To delete the S3 bucket, type the command:
4. You should see an output like this:
BONUS: If the bucket still has objects inside, add --force to first remove all of the objects in the bucket. The bucket will automatically remove itself afterwards. Type the command:
S3 object: You should see an error that says "NoSuchBucket" after running this command
S3 bucket: This command tries to lists all the buckets you have, and in this case you have none! So you should expect nothing to come up:
Congratulations! You have successfully done the following: