Skip to content

compudemy/s3lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 

Repository files navigation

s3lab

Table of Contents

Overview on Amazon S3

Create AWS S3 Bucket and Objects – Hands-On

Step-1: Create an S3 Bucket

Step-2: Create an Object

Step-3: S3 Bucket Versioning

Step-4: S3 Bucket Encryption

AWS S3 Bucket Policies

Create S3 Bucket Policies- Hands-On

Testing AWS Bucket Policy

Conclusion

INTRODUCTION

In this tutorial, we will learn about AWS S3 Buckets and create one. We will also explore S3 versioning and S3 encryption and in the last, we will generate an AWS S3 Bucket policy and apply it to our S3 Bucket. But before getting started let's see what is Amazon s3

Create AWS S3 Bucket and Objects - Hands-On

Step-1: Create an S3 Bucket

First, we will log in to our AWS console then under the Services tab type S3. Currently, we don't have any S3 Buckets available. In order to create an S3 bucket, we will click on Create bucket

image

Here we will enter a bucket name that should be globally unique. Now we will enter a new name for our bucket that is globa After that, we will choose a Region where our bucket will reside. I have chosen it to be US East (Ohio). You can choose a region that is near to you. Note that the S3 console is Global.

image

Here we will Block all public access to our S3 bucket that are the default settings. This will be unchecked if we require public access to our buckets like in the case of hosting a website

image)

Currently, we will keep the Bucket Versioning disabled. We will play with it in the later sections of this tutorial. We can also add tags to our bucket. We will leave the Server-side encryption disabled for now and will see it in the later sections. Now we will click on Create bucket.

image

Here we can see our bucket in the list of available buckets.

image)

Step-2: Upload an Object

Now we will upload objects in our S3 bucket. Note that objects are fundamental entities stored in Amazon s3. Here we will click on Upload.

image

After that, we will click on Add files. We can also add a folder. Here we can see our uploaded object named aws.png.

image

We will leave the remaining settings to default and then click on Upload.

image

Here we can see the details of the object uploaded which include Properties, Permissions, and Versions. Note that we can see an Object URL over here. If we copy this URL and paste it into the browser let's see what happens.

image

The access to the file is denied and the reason is that we blocked public access while creating our S3 bucket. Now let's see what happens if we click on the Open button present in the top right corner.

Image

image

Step-3: S3 Bucket Versioning

Now we will explore the topic of S3 versioning. Note that with versioning we can keep multiple variants of an object in the same bucket. Versioning is used to restore, retrieve and preserve every version of every object and through it, we can also recover from both unintended user actions and application failures.

image

Now we will click on Edit and Enable Bucket Versioning and then click on Save Changes

image

Now we will upload the aws.png file again.

image

Now when we will turn on the Show versions option, we can clearly see both the objects one which we uploaded previously without versioning enabled has Version ID equal to null and the other which we uploaded now has a Version ID.

image)

image

Here for deleting an object permanently we will explicitly select an object and then click on Delete. To confirm deletion we will write permanently delete and then click on Delete objects.

image)

Now we will explore one more thing. After uploading the aws.png object again and disabling the Show versions option we will select the object and then delete it.

image

image

Here we can see that deleting specified objects adds delete markers to them. Now we will type delete and then click on Delete objects.

image

Here we will enable Show versions again to view the delete marker. Note that a delete marker is a placeholder for a versioned object named in a simple DELETE request. When we delete an object with versioning enabled the object is not deleted. The delete marker makes Amazon S3 behave as if the object has been deleted. To restore the object here, we can delete the delete marker.

image)

Step-4: S3 Bucket Encryption

Now we will explore encryption in S3 Buckets. When we will get in the details of an object, we can see that Default Encryption is Disabled that is set at the bucket level. When it is enabled the new objects that are uploaded to the S3 bucket will be encrypted by default.

image

When we will get into the Server-side encryption settings of the object we can specify an Encryption key. It can be either Amazon s3 key (SSE-S3) that is an encryption key created, managed, and used for us by Amazon S3, or an AWS Key Management Service key (SSE-KMS) that is protected by AWS Key Management Service. Note that to upload an object with SSE-C that is a customer-provided encryption key we need to use AWS CLI, AWS SDK, or Amazon S3 REST API.

image

image)

Now when we will go to the bucket level encryption it's disabled by default. We will enable it through which new objects that are stored in the bucket are automatically encrypted. Here also either we can do encryption through SSE-S3 or SSE-KMS. If we want to use SSE-C we will have to use AWS CLI, AWS SDK, or Amazon S3 REST API as stated above.

image

image

Now when we will upload the object again in the bucket, we can see that the Default encryption is enabled.

image

AWS S3 Bucket Policies

According to what is mentioned on the official website of AWS,

A bucket policy is a resource-based AWS Identity and Access Management (IAM) policy. You add a bucket policy to a bucket to grant other AWS accounts or IAM users access permissions for the bucket and the objects in it. Object permissions apply only to the objects that the bucket owner creates.

Create S3 Bucket Policies- Hands-On

In the Permissions section of the bucket we created earlier, we can see that there is no policy written for our bucket. We will click on Edit.

image

This will take us to a new screen where we can see Bucket ARN which we will use when we will generate our policy through the Policy generator. Now we will click on Policy generator.

image

This will lead us to this new screen where we can easily define policy for our bucket through this user-friendly UI. Here we can define policies that control access to AWS products and resources. First we will select the Policy Type that in our case is S3 Bucket Policy. We can also create different types of policies like IAM Policy, an S3 Bucket Policy, an SNS Topic Policy, a VPC Endpoint Policy, and an SQS Policy. Then we will add a statement that is a formal description of single permission. Here for Effect we will select Deny. In Principal we will write . In Actions, we will select PutObject and in Amazon Resource Name we will enter the value we found on the previous screen with the name Bucket ARN. Note that we will add a / after the Bucket ARN value. After that, we will click on Add Conditions.

image

Now here we will define that at what condition we don't want a specific object to be uploaded. We will select the Condition to Null, Key to s3:x-amz-server-side-encryption and Value to true. This means we are denying any object to be uploaded with Key s3:x-amz-server-side-encryption set to Null. Now we click on Add Condition.

image

Here we can see the condition we just defined.

image)

Now we will click on Add Statement. Now we will add another statement in which all the other settings will remain the same except for the condition. In Condition we will select StringNotEquals, for Key, we will select s3:amz-server-side-encryption and the Value will be set to AES256. Now again we will click on Add Condition. Here it means that for Key s3:amz-server-side-encryption if the value is not equal to AES256 then we will not allow the object to get uploaded into our bucket.

image)

Again we will click on Add Statement.

image

Now here we can see both our statements listed. Now we will click on Generate Policy.

image

It returns us a JSON Document which we will use for our S3 Bucket Policy. Note that how easy it is to create policies with Policy Generator.

!image](https://user-images.githubusercontent.com/103466963/171054097-2852b019-6e2d-4f66-aa92-c71c13f9231b.png)

Now we will copy the above JSON document and paste it into our Bucket Policy and after that, we will click on Save changes.

image

Testing AWS Bucket Policy

Now we will upload aws.png again into our S3 bucket but this time without specifying any encryption key. Let's see what happens.

image

We will receive an error message Upload Failed and we can clearly see that the access is denied since our object was not encrypted with AES256 i.e SSE-S3 while we uploaded it.

image

Now we will upload the object again but this time we will specify an encryption key by overriding default encryption bucket settings and then select SSE-S3 and click on Upload.

image

Here we can see that object has been uploaded successfully as it satisfies conditions set in our bucket policy.

image

Conclusion

With this, we have come to the end of our tutorial. In this tutorial, we learned about

S3 Buckets and Objects

S3 Versioning

S3 Encryption

S3 Bucket Policy

LAB 2

Lab Details

This lab walks you through Amazon Simple Storage Service. Amazon S3 has a simple web interface that you can use to store and retrieve any amount of data(at any time) from anywhere on the web. In this lab we will demonstrate AWS S3 by creating a sample S3 bucket, uploading an object to the S3 bucket and setting up the bucket permission and policy.

Tasks Log into the AWS Management Console.

Create an S3 bucket.

Upload an object to S3 Bucket.

Access the object on the browser.

Change S3 object permissions.

Setup the bucket policy and permission and test the object accessibility.

image

Set up the bucket name. S3 bucket name are globally unique, choose a name which is available. Click on Next

image

Leave other settings as default and click on Next

image

Leave other settings as default and click on Next

image

Leave other settings as default and click on Create bucket

image

Click on your bucket name.

image

Click on Upload

image

Click on Add files, and choose a file from your computer.

image

After choosing your file, click on Next

image

Click on Next

image

Click on Next

image

Click on Upload.

image

You could see the uploading procession below.

image

Now you have a private S3 bucket with a private object uploaded, which means you cannot visit it through Internet.

Change Bucket Permission

Change the permission of the bucket to make the image available publicly.

Click on your object in the bucket, You will see the object details like owner, size, link, etc.

image

A URL will be listed under Object URL

https://mys3bucketwhizlabs.s3.amazonaws.com/smiley.jpg

Open image Link in a new tab. You will see an AccessDenied message, which means the object is not publicly accessible.

image

Go back to your bucket and click on Permissions

image

Click on Everyone under the Public access, and click on Read object on the right of pop-up window. Then click on Save

image

Now its state switches to Read Object - Yes

image

Click on Overview, and click on your Object URL again

image

Create a Bucket Policy

In the previous step, you granted read access only to a specific object.

If you wish to make all objects inside a bucket available publicly, you can achieve this by creating a bucket policy.

Go to the bucket list and click on your bucket name

image

Click the Permissions tab, then configure the following

image

Click on Bucket Policy

image

A blank Bucket policy editor is displayed.

Copy the ARN of your bucket to the clipboard.e.g, arn:aws:s3:::s3bucket180

Replace your bucket ARN with the ARN listed in the JSON below, then copy the entire policy.

Screen Shot 2022-06-20 at 19 51 15

Click on Save

image

Test Public Access

Go back to your bucket list, then click on your bucket.

Upload another file.

Leave all of the settings as default

image

Click on your new object, and click on the Object URL

image Success

Completion and Conclusion

You have successfully created a new AWS S3 Bucket.

You have successfully uploaded an image to the S3 bucket.

You have learned to change S3 object permissions.

You have learned how to create an S3 bucket policy.

How to enable versioning Amazon S3

https://play.whizlabs.com/site/task_details?lab_type=1&task_id=21&quest_id=35

Lab Details

This lab walks you through the steps on how to enables versioning on an AWS S3 Bucket.

Versioning allows you to keep multiple versions of an object in one bucket.

Task Details

Log into the AWS Management Console.

Create an S3 bucket.

Enable object versioning on the bucket.

Upload a text file to the S3 Bucket.

Test object versioning by changing the text file and re-uploading it.

Architecture Diagram

Screen Shot 2022-06-20 at 20 09 02

S3 Configuration

Service -> S3

Create an S3 Bucket

On the S3 dashboard, click on Create bucket and fill in the bucket details.

image

Bucket name: Enter yourBucketName

Note: S3 bucket names are globally unique, choose a name which is available.

Region: Select US East (N. Virginia)

Leave other settings as default.

Click on Create

image

Close the pop up window if it’s still open.

image

Enable Versioning on the S3 bucket

Go to the bucket list and click on your bucket name whizlabs234

image

Click on Properties.

image

Choose Versioning.

image

Choose Enable versioning and click on Save.

image

Now versioning on the S3 bucket is enabled.

image

Upload an object

Upload any file from your local machine.

On the S3 Buck list page, Click on youBucketName

Click on Overview tab.

Click on the Upload button.

image

image

Click on the Add files button.

image

Browse for the file you want to upload.

image

Click on Next and Grant public read access to this project(s)

Click on the Upload button.

image

You can watch the progress of the upload from within the transfer panel at the bottom of the screen.

If it’s a small file, you might not see the transfer.

Once your file has been uploaded, it will be displayed in the bucket.

image

Make the bucket public with a Bucket Policy

Go to the bucket list and click on your bucket name.

image

Click the Permissions tab to configure your bucket:

In the Permissions tab, click on Bucket Polity

A blank Bucket policy editor is displayed.

Before creating the policy, you will need to copy the ARN (Amazon Resource Name) of your bucket.

Copy the ARN of your bucket to the clipboard. It is displayed at the top of the policy editor. its look like ARN: arn:aws:s3:::your-bucket-name

image

image

In the policy below, update your bucket ARN in the Resource key value and copy the policy code.

Paste the bucket policy into the Bucket policy editor.

Screen Shot 2022-06-20 at 20 51 06

image

Click on Save

image

Click on Overview

image

Now open the text file link in your browser and you should see the text in file.

image

image

Upload the same object with different content

Upload the same file with different content from your local machine.

On the S3 Buck list page, Click on youBucketName

Click on Overview tab.

Click on the Upload button.

image

image

Click on the Add files button.

image

Browse for the file you want to upload.

image

Click on Next and Grant public read access to this project(s)

Click on the Upload button.

image

You should see the latest version of the file you uploaded.

image

image

Testing a previous version of the file

To enable the old version of the file, we need to delete the latest version of the file.

Click on object URL

image

image

Click on the file name.

On the top section (next to the object name) you can find a drop down of all file versions called

Latest version

image

Click on the drop down and delete the latest version of your file.

image

image

Completion and Conclusion

You have successfully created an S3 Bucket.

You have successfully enabled Object Versioning on the Bucket.

You have successfully uploaded a test file into the Bucket and tested its versioning.

Creating an S3 Lifecycle Policy

https://play.whizlabs.com/site/task_details?lab_type=1&task_id=45&quest_id=35

Lab Details

This Lab walks you through the steps on how to create a Lifecycle Rule for an object in an S3 Bucket.

Lab Tasks

Log into the AWS Management Console.

Create S3 Bucket and upload and object into the bucket.

Create a Lifecycle Rule on the object.

Create Transition types.

Create Transition Expiration.

Test the Lifecycle Rule on the uploaded object.

S3 Configuration

Create an S3 Bucket

On the S3 dashboard, click on Create bucket and fill in the bucket details.

image

Bucket name: Enter inputYourBucketName

Note: S3 bucket names are globally unique, choose a name which is available.

Region: Select US East (N. Virginia)

Leave other settings as default.

Click on Create

image

Close the pop up window if it’s still open.

image

Upload an object

Upload any file from your local machine.

On the S3 Buck list page, Click on youBucketName

Click on Overview tab.

Click on the Upload button.

image

image

Click on the Add files button.

image

Browse for the file you want to upload.

image

Click on Next and Grant public read access to this project(s)

Click on the Upload button.

image

You can watch the progress of the upload from within the transfer panel at the bottom of the screen.

If it’s a small file, you might not see the transfer.

Once your file has been uploaded, it will be displayed in the bucket.

image

Creating a Lifecycle Rule

Click on the Management tab.

image

Click on Add lifecycle rule to create a lifecycle rule for the uploaded object.

image

Enter the rule name: tmpLifecycle

Add a filter to limit the scope to prefix/tags: tmp

Choose prefix tmp from the drop-down and click Next.

image

Storage class transition: Select Current version

image

For current versions of objects: Click Add transition

Note: currently versioning is disabled so we can’t access previous versions of the object. Object Creation: Select Transition to One Zone-IA after from the drop-down list.

Days after creation: Enter 35. Click on Add transition.

Select Transition to Glacier after from the drop-down list. When asked for a number of days before moving to Glacier, enter 90.

Click on the checkbox saying I acknowledge that this lifecycle rule will increase the one-time lifecycle request cost if it transitions to small objects.

Click on Next.

Note:

Initially, when the object is uploaded, it will be in the standard storage class.

When we create a LifeCycle Policy, the object uploaded using the Lifecycle rule will be migrated to One Zone-IA after 35 days. This means the object will be available only in a Single Availability Zone after 35 days.

After 90 days, our object will be migrated to Glacier. This means our object will be in an archived state. You would have to retrieve the object from Glacier before accessing it.

image

Create Expiration: Select Current version

Expire the current version of an object: Enter 120.

Select the Clean up incomplete multipart uploads check-box.

Note: Leave the number of days at 7 (Default value). This means that objects which are not properly uploaded will be deleted after 7 days.

image

Before saving, verify the configurations (you can go back and edit later if you need to change anything). Click Edit.

Click on Save.

image

The Lifecycle Rule for our object will now be created and enabled.

image

Completion and Conclusion

You have successfully used the AWS management console to create a Lifecycle Rule for the object in the S3 bucket.

You have configured the details of a Lifecycle Rule.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published